Fix a tricky thread synchronization bug.

If a command ran to completion before the thread calling
fifo_add_command woke up, that thread would wait forever
for the command to start, never realizing that it had already
finished.
This commit is contained in:
Christopher Brannon
2016-10-10 21:02:15 -07:00
parent 0436ae71c0
commit 1d8cec684b
+2 -2
View File
@@ -113,7 +113,7 @@ espeak_ng_STATUS fifo_add_command(t_espeak_command *the_command)
my_start_is_required = 1;
pthread_cond_signal(&my_cond_start_is_required);
while (!my_command_is_running) {
while (my_start_is_required && !my_command_is_running) {
if((status = pthread_cond_wait(&my_cond_command_is_running, &my_mutex)) != ENS_OK && errno != EINTR) {
pthread_mutex_unlock(&my_mutex);
return status;
@@ -149,7 +149,7 @@ espeak_ng_STATUS fifo_add_commands(t_espeak_command *command1, t_espeak_command
my_start_is_required = 1;
pthread_cond_signal(&my_cond_start_is_required);
while (!my_command_is_running) {
while (my_start_is_required && !my_command_is_running) {
if((status = pthread_cond_wait(&my_cond_command_is_running, &my_mutex)) != ENS_OK && errno != EINTR) {
pthread_mutex_unlock(&my_mutex);
return status;