diff options
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 222b188b..b48b954c 100755 --- a/audio/liba2dp.c +++ b/audio/liba2dp.c @@ -917,7 +917,7 @@ static int wait_for_start(struct bluetooth_data *data, int timeout) ts.tv_nsec = (tv.tv_usec + (timeout % 1000) * 1000L ) * 1000L; pthread_mutex_lock(&data->mutex); - while (state != A2DP_STATE_STARTED && !err) { + while (state != A2DP_STATE_STARTED) { if (state == A2DP_STATE_NONE) set_command(data, A2DP_CMD_INIT); else if (state == A2DP_STATE_INITIALIZED) @@ -925,9 +925,22 @@ static int wait_for_start(struct bluetooth_data *data, int timeout) else if (state == A2DP_STATE_CONFIGURED) { __set_command(data, A2DP_CMD_START); } +again: + err = pthread_cond_timedwait(&data->client_wait, &data->mutex, &ts); + if (err) { + /* don't timeout if we're done */ + if (data->state == A2DP_STATE_STARTED) { + err = 0; + break; + } + if (err == ETIMEDOUT) + break; + goto again; + } + + if (state == data->state) + goto again; - while ((err = pthread_cond_timedwait(&data->client_wait, &data->mutex, &ts)) - == EINTR) ; state = data->state; if (state == A2DP_STATE_NONE) { |