Commit b6eae69c authored by Andreas Schmidt's avatar Andreas Schmidt
Browse files

Stop saving lock positions to stack variables.

parent bd741649
......@@ -111,19 +111,17 @@ int PrrtSocket_send(PrrtSocket *sock_ptr, const uint8_t *data, const size_t data
int32_t PrrtSocket_recv(PrrtSocket *sock_ptr, void *buf_ptr) {
check(sock_ptr->is_sender == false, "Cannot receive on sender socket.")
pthread_mutex_t filledMutex = sock_ptr->inQueueFilledMutex;
pthread_mutex_t closingMutex = sock_ptr->closingMutex;
while (1) {
check(pthread_mutex_lock(&filledMutex) == 0, "Lock failed.");
check(pthread_mutex_lock(&sock_ptr->inQueueFilledMutex) == 0, "Lock failed.");
while (List_count(sock_ptr->inQueue) == 0) {
check(pthread_mutex_lock(&closingMutex) == 0, "Lock failed.");
check(pthread_mutex_lock(&sock_ptr->closingMutex) == 0, "Lock failed.");
if (sock_ptr->closing) {
check(pthread_mutex_unlock(&closingMutex) == 0, "Unlock failed.");
check(pthread_mutex_unlock(&filledMutex) == 0, "Unlock failed.");
check(pthread_mutex_unlock(&sock_ptr->closingMutex) == 0, "Unlock failed.");
check(pthread_mutex_unlock(&sock_ptr->inQueueFilledMutex) == 0, "Unlock failed.");
return -1;
}
check(pthread_mutex_unlock(&closingMutex) == 0, "Unlock failed.");
check(pthread_cond_wait(&sock_ptr->inQueueFilledCv, &filledMutex) == 0, "Wait failed.");
check(pthread_mutex_unlock(&sock_ptr->closingMutex) == 0, "Unlock failed.");
check(pthread_cond_wait(&sock_ptr->inQueueFilledCv, &sock_ptr->inQueueFilledMutex) == 0, "Wait failed.");
}
PrrtPacket *packet = List_shift(sock_ptr->inQueue);
......@@ -131,7 +129,7 @@ int32_t PrrtSocket_recv(PrrtSocket *sock_ptr, void *buf_ptr) {
PrrtPacket_copy_payload_to_buffer(buf_ptr, packet, PRRT_PACKET_DATA_HEADER_SIZE);
PrrtPacket_destroy(packet);
check(pthread_mutex_unlock(&filledMutex) == 0, "Unlock failed.");
check(pthread_mutex_unlock(&sock_ptr->inQueueFilledMutex) == 0, "Unlock failed.");
return len;
}
error:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment