Browse Source

Fix hang when waiting for condition variables.

master
Rui Batista 8 years ago
parent
commit
34f315363b
1 changed files with 8 additions and 5 deletions
  1. 8
    5
      src/libespeak-ng/fifo.c

+ 8
- 5
src/libespeak-ng/fifo.c View File



// leave once the thread is actually started // leave once the thread is actually started
assert(-1 != pthread_mutex_lock(&my_mutex)); assert(-1 != pthread_mutex_lock(&my_mutex));
while ((my_stop_is_acknowledged == 0) || ((pthread_cond_wait(&my_cond_stop_is_acknowledged, &my_mutex) == -1) && errno == EINTR)) while (my_stop_is_acknowledged == 0)
continue; // Restart when interrupted by handler while((pthread_cond_wait(&my_cond_stop_is_acknowledged, &my_mutex) == -1) && errno == EINTR)
;
my_stop_is_acknowledged = 0; my_stop_is_acknowledged = 0;
pthread_mutex_unlock(&my_mutex); pthread_mutex_unlock(&my_mutex);
} }
} }


if (a_command_is_running) { if (a_command_is_running) {
while ((my_stop_is_acknowledged == 0) || ((pthread_cond_wait(&my_cond_stop_is_acknowledged, &my_mutex) == -1) && errno == EINTR)) while (my_stop_is_acknowledged == 0)
continue; // Restart when interrupted by handler while((pthread_cond_wait(&my_cond_stop_is_acknowledged, &my_mutex) == -1) && errno == EINTR)
continue; // Restart when interrupted by handler
} }


my_stop_is_required = 0; my_stop_is_required = 0;
assert(!a_status); assert(!a_status);


if (!a_start_is_required) { if (!a_start_is_required) {
while ((my_start_is_required == 0) || ((pthread_cond_wait(&my_cond_start_is_required, &my_mutex) == -1) && errno == EINTR)) while (my_start_is_required == 0)
while((pthread_cond_wait(&my_cond_start_is_required, &my_mutex) == -1) && errno == EINTR)
continue; // Restart when interrupted by handler continue; // Restart when interrupted by handler
} }



Loading…
Cancel
Save