Commit cab7c70a authored by Andreas Schmidt's avatar Andreas Schmidt

Checks and consistent PrrtSocket_closing() calls.

parent 8edee7e2
......@@ -291,7 +291,7 @@ void *receive_data_loop(void *ptr) {
struct timespec packet_recv_timestamp;
uint64_t packet_recv_cyclestamp = 0;
receive_from_socket(s, buffer, &n, &remote, &addrlen, &packet_recv_timestamp, &packet_recv_cyclestamp);
if (atomic_load_explicit(&s->closing, memory_order_acquire)) {
if (PrrtSocket_closing(s)) {
break;
}
......
......@@ -53,6 +53,7 @@ PrrtSocket *PrrtSocket_create(prrtByteCount_t maximum_payload_size, prrtTimedelt
PrrtClock_init(&s->clock);
s->isBound = false;
atomic_store_explicit(&s->closing, false, memory_order_release);
s->receiver = NULL;
uint8_t n_cycle[1] = { N_START - K_START };
......@@ -320,14 +321,14 @@ int PrrtSocket_interrupt(PrrtSocket *s) {
if (s->sendDataThread != 0) {
check(pthread_cancel(s->sendDataThread) == EXIT_SUCCESS, "Cancel failed.");
check(pthread_join(s->sendDataThread, res) == EXIT_SUCCESS, "Join failed.");
pthread_attr_destroy(s->sendDataThreadAttr);
check(pthread_attr_destroy(s->sendDataThreadAttr) == EXIT_SUCCESS, "Destroy failed.");
s->sendDataThread = 0;
}
if (s->receiveDataThread != 0) {
check(pthread_cancel(s->receiveDataThread) == EXIT_SUCCESS, "Cancel failed.");
check(pthread_join(s->receiveDataThread, res) == EXIT_SUCCESS, "Join failed.");
pthread_attr_destroy(s->receiveDataThreadAttr);
check(pthread_attr_destroy(s->receiveDataThreadAttr) == EXIT_SUCCESS, "Destroy failed.");
s->receiveDataThread = 0;
}
......@@ -339,7 +340,7 @@ int PrrtSocket_interrupt(PrrtSocket *s) {
int PrrtSocket_close(PrrtSocket *s) {
debug(DEBUG_SOCKET, "Closing socket.");
if (!atomic_load_explicit(&s->closing, memory_order_acquire)) {
if (!PrrtSocket_closing(s)) {
check(PrrtSocket_interrupt(s) == EXIT_SUCCESS, "Interrupt failed.");
}
......
......@@ -24,10 +24,14 @@ PrrtReceptionTable *PrrtReceptionTable_create(void) {
}
bool PrrtReceptionTable_destroy(PrrtReceptionTable *t) {
pthread_mutex_destroy(&t->lock);
check(pthread_mutex_destroy(&t->lock) == EXIT_SUCCESS, "Destroy failed.");
Bitmap_destroy(t->bitmap);
free(t);
return true;
error:
PERROR("PrrtReceptionTable_destroy failed.%s", "");
return false;
}
bool PrrtReceptionTable_mark_received(PrrtReceptionTable *t, prrtSequenceNumber_t markedNumber) {
......@@ -48,7 +52,6 @@ bool PrrtReceptionTable_mark_received(PrrtReceptionTable *t, prrtSequenceNumber_
t->start = new_start;
}
check(pthread_mutex_unlock(&t->lock) == EXIT_SUCCESS, "Lock failed.");
return 0;
error:
......
Markdown is supported
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