Skip to content

Commit

Permalink
Safeguard cancellation zone for IO threads
Browse files Browse the repository at this point in the history
Thread cancellation is allowed only in the safety zone - poll and read
after the poll. It is easier to maintain strictly defined place for such
a potentially destructive functionality - resources can not be allocated
in such a zone. So, we have to make sure, that if we jump off this zone
by the usage of break or goto statement, the code which follows will not
be canceled - resources can be safely released.
  • Loading branch information
arkq committed Nov 23, 2016
1 parent 045503c commit e3bb192
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ void *io_thread_a2dp_sink_sbc(void *arg) {
}

fail:
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
pthread_cleanup_pop(1);
pthread_cleanup_pop(1);
pthread_cleanup_pop(1);
Expand Down Expand Up @@ -599,6 +600,7 @@ void *io_thread_a2dp_source_sbc(void *arg) {
}

fail:
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
pthread_cleanup_pop(1);
pthread_cleanup_pop(1);
pthread_cleanup_pop(1);
Expand Down Expand Up @@ -741,6 +743,7 @@ void *io_thread_a2dp_sink_aac(void *arg) {
}

fail:
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
pthread_cleanup_pop(1);
pthread_cleanup_pop(1);
fail_init:
Expand Down Expand Up @@ -1023,6 +1026,7 @@ void *io_thread_a2dp_source_aac(void *arg) {
}

fail:
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
pthread_cleanup_pop(1);
pthread_cleanup_pop(1);
fail_init:
Expand Down Expand Up @@ -1168,6 +1172,7 @@ void *io_thread_rfcomm(void *arg) {
}

fail:
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
pthread_cleanup_pop(1);
return NULL;
}
Expand Down

0 comments on commit e3bb192

Please sign in to comment.