Browse Source

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.
master
Christopher Brannon 8 years ago
parent
commit
1d8cec684b
1 changed files with 2 additions and 2 deletions
  1. 2
    2
      src/libespeak-ng/fifo.c

+ 2
- 2
src/libespeak-ng/fifo.c 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;

Loading…
Cancel
Save