diff options
author | Ian Kent <raven@themaw.net> | 2009-09-28 23:47:44 +0800 |
---|---|---|
committer | Jaikumar Ganesh <jaikumar@google.com> | 2011-05-25 11:51:54 -0700 |
commit | 6782d7bd225048e49ff485d06d8da5be8472fcf3 (patch) | |
tree | c2d86a8af0d3b0967f6c4d22464a7be90b97c230 /audio | |
parent | 281c324f0ba38b0720884b53d465b1420fac616a (diff) | |
download | bluez-6782d7bd225048e49ff485d06d8da5be8472fcf3.tar.gz |
bluez a2dp - fix a2dp_thread() spurious wakeup
When waiting on a condition is is possble to receive spurious
wake ups. Use the fact that when we poke the state machine the
command must have changed to deal with this.
Change-Id: I0ed2f2a15c15dea30cb1d5cf3b67c8549d6802d4
Diffstat (limited to 'audio')
-rwxr-xr-x | audio/liba2dp.c | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/audio/liba2dp.c b/audio/liba2dp.c index a46dcf00..d7cab1bd 100755 --- a/audio/liba2dp.c +++ b/audio/liba2dp.c @@ -937,6 +937,7 @@ static int wait_for_start(struct bluetooth_data *data, int timeout) static void* a2dp_thread(void *d) { struct bluetooth_data* data = (struct bluetooth_data*)d; + a2dp_command_t command = A2DP_CMD_NONE; DBG("a2dp_thread started"); prctl(PR_SET_NAME, "a2dp_thread", 0, 0, 0); @@ -948,10 +949,21 @@ static void* a2dp_thread(void *d) while (1) { - a2dp_command_t command; + while (1) { + pthread_cond_wait(&data->thread_wait, &data->mutex); - pthread_cond_wait(&data->thread_wait, &data->mutex); - command = data->command; + /* Initialization needed */ + if (data->state == A2DP_STATE_NONE && + data->command != A2DP_CMD_QUIT) { + bluetooth_init(data); + } + + /* New state command signaled */ + if (command != data->command) { + command = data->command; + break; + } + } switch (command) { case A2DP_CMD_INIT: @@ -1010,6 +1022,7 @@ int a2dp_init(int rate, int channels, a2dpData* dataPtr) data->server.fd = -1; data->stream.fd = -1; data->state = A2DP_STATE_NONE; + data->command = A2DP_CMD_NONE; strncpy(data->address, "00:00:00:00:00:00", 18); data->rate = rate; |