Skip to content

Commit

Permalink
Refactor transport thread state management
Browse files Browse the repository at this point in the history
Instead of using pthread thread ID for checking if the thread is
running, use dedicated transport thread state variable.

Also, in order to cancel IO threads in a more reliable way, transport
thread manager will cancel the IO thread only if it was marked for
stopping. This will prevent unintended thread cancellation caused by
buffered commands in the transport thread manager queue.

Fixes arkq#585
  • Loading branch information
arkq committed Feb 13, 2023
1 parent 6909dc6 commit 0770180
Show file tree
Hide file tree
Showing 18 changed files with 182 additions and 125 deletions.
1 change: 1 addition & 0 deletions .github/spellcheck-wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ docutils
dpsnk
dpsrc
DYN
EINVAL
ENODEV
EP
EPIPE
Expand Down
4 changes: 2 additions & 2 deletions src/a2dp-aac.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ void *a2dp_aac_enc_thread(struct ba_transport_thread *th) {
AACENC_OutArgs out_args = { 0 };

debug_transport_thread_loop(th, "START");
for (ba_transport_thread_set_state_running(th);;) {
for (ba_transport_thread_state_set_running(th);;) {

ssize_t samples;
if ((samples = io_poll_and_read_pcm(&io, &t->a2dp.pcm,
Expand Down Expand Up @@ -483,7 +483,7 @@ void *a2dp_aac_dec_thread(struct ba_transport_thread *th) {
int markbit_quirk = -3;

debug_transport_thread_loop(th, "START");
for (ba_transport_thread_set_state_running(th);;) {
for (ba_transport_thread_state_set_running(th);;) {

ssize_t len = ffb_blen_in(&bt);
if ((len = io_poll_and_read_bt(&io, th, bt.data, len)) <= 0) {
Expand Down
4 changes: 2 additions & 2 deletions src/a2dp-aptx-hd.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ void *a2dp_aptx_hd_enc_thread(struct ba_transport_thread *th) {
rtp_state_init(&rtp, samplerate, samplerate);

debug_transport_thread_loop(th, "START");
for (ba_transport_thread_set_state_running(th);;) {
for (ba_transport_thread_state_set_running(th);;) {

ssize_t samples;
if ((samples = io_poll_and_read_pcm(&io, &t->a2dp.pcm,
Expand Down Expand Up @@ -269,7 +269,7 @@ void *a2dp_aptx_hd_dec_thread(struct ba_transport_thread *th) {
rtp_state_init(&rtp, samplerate, samplerate);

debug_transport_thread_loop(th, "START");
for (ba_transport_thread_set_state_running(th);;) {
for (ba_transport_thread_state_set_running(th);;) {

ssize_t len = ffb_blen_in(&bt);
if ((len = io_poll_and_read_bt(&io, th, bt.data, len)) <= 0) {
Expand Down
4 changes: 2 additions & 2 deletions src/a2dp-aptx.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ void *a2dp_aptx_enc_thread(struct ba_transport_thread *th) {
}

debug_transport_thread_loop(th, "START");
for (ba_transport_thread_set_state_running(th);;) {
for (ba_transport_thread_state_set_running(th);;) {

ssize_t samples;
if ((samples = io_poll_and_read_pcm(&io, &t->a2dp.pcm,
Expand Down Expand Up @@ -244,7 +244,7 @@ void *a2dp_aptx_dec_thread(struct ba_transport_thread *th) {
}

debug_transport_thread_loop(th, "START");
for (ba_transport_thread_set_state_running(th);;) {
for (ba_transport_thread_state_set_running(th);;) {

ssize_t len = ffb_blen_in(&bt);
if ((len = io_poll_and_read_bt(&io, th, bt.data, len)) <= 0) {
Expand Down
4 changes: 2 additions & 2 deletions src/a2dp-faststream.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ void *a2dp_faststream_enc_thread(struct ba_transport_thread *th) {
}

debug_transport_thread_loop(th, "START");
for (ba_transport_thread_set_state_running(th);;) {
for (ba_transport_thread_state_set_running(th);;) {


ssize_t samples = ffb_len_in(&pcm);
Expand Down Expand Up @@ -258,7 +258,7 @@ void *a2dp_faststream_dec_thread(struct ba_transport_thread *th) {
}

debug_transport_thread_loop(th, "START");
for (ba_transport_thread_set_state_running(th);;) {
for (ba_transport_thread_state_set_running(th);;) {

ssize_t len = ffb_blen_in(&bt);
if ((len = io_poll_and_read_bt(&io, th, bt.tail, len)) <= 0) {
Expand Down
4 changes: 2 additions & 2 deletions src/a2dp-lc3plus.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ void *a2dp_lc3plus_enc_thread(struct ba_transport_thread *th) {
rtp_state_init(&rtp, samplerate, rtp_ts_clockrate);

debug_transport_thread_loop(th, "START");
for (ba_transport_thread_set_state_running(th);;) {
for (ba_transport_thread_state_set_running(th);;) {

ssize_t samples;
if ((samples = io_poll_and_read_pcm(&io, &t->a2dp.pcm,
Expand Down Expand Up @@ -457,7 +457,7 @@ void *a2dp_lc3plus_dec_thread(struct ba_transport_thread *th) {
bool rtp_media_fragment_skip = false;

debug_transport_thread_loop(th, "START");
for (ba_transport_thread_set_state_running(th);;) {
for (ba_transport_thread_state_set_running(th);;) {

ssize_t len = ffb_blen_in(&bt);
if ((len = io_poll_and_read_bt(&io, th, bt.data, len)) <= 0) {
Expand Down
4 changes: 2 additions & 2 deletions src/a2dp-ldac.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ void *a2dp_ldac_enc_thread(struct ba_transport_thread *th) {
rtp_state_init(&rtp, samplerate, samplerate);

debug_transport_thread_loop(th, "START");
for (ba_transport_thread_set_state_running(th);;) {
for (ba_transport_thread_state_set_running(th);;) {

ssize_t samples;
if ((samples = io_poll_and_read_pcm(&io, &t->a2dp.pcm,
Expand Down Expand Up @@ -328,7 +328,7 @@ void *a2dp_ldac_dec_thread(struct ba_transport_thread *th) {
rtp_state_init(&rtp, samplerate, samplerate);

debug_transport_thread_loop(th, "START");
for (ba_transport_thread_set_state_running(th);;) {
for (ba_transport_thread_state_set_running(th);;) {

ssize_t len = ffb_blen_in(&bt);
if ((len = io_poll_and_read_bt(&io, th, bt.data, len)) <= 0) {
Expand Down
4 changes: 2 additions & 2 deletions src/a2dp-mpeg.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ void *a2dp_mp3_enc_thread(struct ba_transport_thread *th) {
rtp_state_init(&rtp, samplerate, 90000);

debug_transport_thread_loop(th, "START");
for (ba_transport_thread_set_state_running(th);;) {
for (ba_transport_thread_state_set_running(th);;) {

ssize_t samples;
if ((samples = io_poll_and_read_pcm(&io, &t->a2dp.pcm,
Expand Down Expand Up @@ -480,7 +480,7 @@ void *a2dp_mpeg_dec_thread(struct ba_transport_thread *th) {
rtp_state_init(&rtp, samplerate, 90000);

debug_transport_thread_loop(th, "START");
for (ba_transport_thread_set_state_running(th);;) {
for (ba_transport_thread_state_set_running(th);;) {

ssize_t len = ffb_blen_in(&bt);
if ((len = io_poll_and_read_bt(&io, th, bt.data, len)) <= 0) {
Expand Down
4 changes: 2 additions & 2 deletions src/a2dp-sbc.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ void *a2dp_sbc_enc_thread(struct ba_transport_thread *th) {
rtp_state_init(&rtp, samplerate, samplerate);

debug_transport_thread_loop(th, "START");
for (ba_transport_thread_set_state_running(th);;) {
for (ba_transport_thread_state_set_running(th);;) {

ssize_t samples;
if ((samples = io_poll_and_read_pcm(&io, &t->a2dp.pcm,
Expand Down Expand Up @@ -353,7 +353,7 @@ void *a2dp_sbc_dec_thread(struct ba_transport_thread *th) {
#endif

debug_transport_thread_loop(th, "START");
for (ba_transport_thread_set_state_running(th);;) {
for (ba_transport_thread_state_set_running(th);;) {

ssize_t len = ffb_blen_in(&bt);
if ((len = io_poll_and_read_bt(&io, th, bt.data, len)) <= 0) {
Expand Down
Loading

0 comments on commit 0770180

Please sign in to comment.