bluez a2dp - fix wait_for_start() spurious wakeup

When waiting on a condition is is possble to receive spurious
wake ups. Deal with this in wait_for_start().

Change-Id: I678e9d7831333d9b8baa31e9b0ec2597ca9263cd
diff --git a/audio/liba2dp.c b/audio/liba2dp.c
index 222b188..b48b954 100755
--- a/audio/liba2dp.c
+++ b/audio/liba2dp.c
@@ -917,7 +917,7 @@
 	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 @@
 		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;
+		}
 
-		while ((err = pthread_cond_timedwait(&data->client_wait, &data->mutex, &ts))
-				== EINTR) ;
+		if (state == data->state)
+			goto again;
+
 		state = data->state;
 
 		if (state == A2DP_STATE_NONE) {