From 1d8cec684b6fe3b893be4b9112eeb2490a988997 Mon Sep 17 00:00:00 2001 From: Christopher Brannon Date: Mon, 10 Oct 2016 20:59:38 -0700 Subject: [PATCH] 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. --- src/libespeak-ng/fifo.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libespeak-ng/fifo.c b/src/libespeak-ng/fifo.c index 822c8276..33177434 100644 --- a/src/libespeak-ng/fifo.c +++ b/src/libespeak-ng/fifo.c @@ -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;