mirror of
https://github.com/linux-speakup/espeakup.git
synced 2026-08-09 09:19:09 +02:00
fixup! softsynth: bound the wait for espeak to acknowledge a stop request
This commit is contained in:
parent
71d0e1fa2a
commit
6835449642
2 changed files with 15 additions and 2 deletions
|
|
@ -24,6 +24,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/file.h>
|
#include <sys/file.h>
|
||||||
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "espeakup.h"
|
#include "espeakup.h"
|
||||||
|
|
@ -41,7 +42,8 @@ espeak_AUDIO_OUTPUT audio_mode;
|
||||||
|
|
||||||
pthread_cond_t runner_awake = PTHREAD_COND_INITIALIZER;
|
pthread_cond_t runner_awake = PTHREAD_COND_INITIALIZER;
|
||||||
pthread_cond_t wake_stop = PTHREAD_COND_INITIALIZER;
|
pthread_cond_t wake_stop = PTHREAD_COND_INITIALIZER;
|
||||||
pthread_cond_t stop_acknowledged = PTHREAD_COND_INITIALIZER;
|
/* Initialized in main: uses the monotonic clock for timed waits. */
|
||||||
|
pthread_cond_t stop_acknowledged;
|
||||||
pthread_mutex_t queue_guard = PTHREAD_MUTEX_INITIALIZER;
|
pthread_mutex_t queue_guard = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
|
||||||
int espeakup_start_daemon(void)
|
int espeakup_start_daemon(void)
|
||||||
|
|
@ -147,6 +149,17 @@ int main(int argc, char **argv)
|
||||||
struct synth_t s = {
|
struct synth_t s = {
|
||||||
.voice = "",
|
.voice = "",
|
||||||
};
|
};
|
||||||
|
pthread_condattr_t monotonic_attr;
|
||||||
|
|
||||||
|
/* Condition variables used with pthread_cond_timedwait must use the
|
||||||
|
* monotonic clock, so that wall-clock adjustments (NTP, an
|
||||||
|
* installer setting the system time) cannot make the timeouts fire
|
||||||
|
* too early or far too late. */
|
||||||
|
pthread_condattr_init(&monotonic_attr);
|
||||||
|
pthread_condattr_setclock(&monotonic_attr, CLOCK_MONOTONIC);
|
||||||
|
pthread_cond_init(&stop_acknowledged, &monotonic_attr);
|
||||||
|
pthread_condattr_destroy(&monotonic_attr);
|
||||||
|
|
||||||
synth_queue = new_queue();
|
synth_queue = new_queue();
|
||||||
|
|
||||||
if (!synth_queue) {
|
if (!synth_queue) {
|
||||||
|
|
|
||||||
|
|
@ -237,7 +237,7 @@ static void request_espeak_stop(void)
|
||||||
stop_requested = 1;
|
stop_requested = 1;
|
||||||
pthread_cond_signal(&runner_awake); // Wake runner, if necessary.
|
pthread_cond_signal(&runner_awake); // Wake runner, if necessary.
|
||||||
pthread_cond_signal(&wake_stop); // Wake runner, if necessary.
|
pthread_cond_signal(&wake_stop); // Wake runner, if necessary.
|
||||||
clock_gettime(CLOCK_REALTIME, &timeout);
|
clock_gettime(CLOCK_MONOTONIC, &timeout);
|
||||||
timeout.tv_sec += stopAckTimeout;
|
timeout.tv_sec += stopAckTimeout;
|
||||||
while (should_run && stop_requested && err != ETIMEDOUT)
|
while (should_run && stop_requested && err != ETIMEDOUT)
|
||||||
// wait for acknowledgement.
|
// wait for acknowledgement.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue