static void set_state(struct bluetooth_data *data, a2dp_state_t state)
{
- pthread_mutex_lock(&data->mutex);
data->state = state;
pthread_cond_signal(&data->client_wait);
- pthread_mutex_unlock(&data->mutex);
}
static void set_command(struct bluetooth_data *data, a2dp_command_t command)
DBG("a2dp_thread started");
prctl(PR_SET_NAME, "a2dp_thread", 0, 0, 0);
+ pthread_mutex_lock(&data->mutex);
+
+ data->started = 1;
+ pthread_cond_signal(&data->thread_start);
+
while (1)
{
a2dp_command_t command;
- pthread_mutex_lock(&data->mutex);
- if (!data->started) {
- data->started = 1;
- pthread_cond_signal(&data->thread_start);
- }
pthread_cond_wait(&data->thread_wait, &data->mutex);
command = data->command;
- pthread_mutex_unlock(&data->mutex);
if (data->state == A2DP_STATE_NONE && command != A2DP_CMD_QUIT)
bluetooth_init(data);
}
done:
+ pthread_mutex_unlock(&data->mutex);
DBG("a2dp_thread finished");
return NULL;
}
goto error;
}
+ /* Make sure the state machine is ready and waiting */
while (!data->started) {
pthread_cond_wait(&data->thread_start, &data->mutex);
}
+ /* Poke the state machine to get it going */
+ pthread_cond_signal(&data->thread_wait);
+
pthread_mutex_unlock(&data->mutex);
*dataPtr = data;