From ac9e12414b2f4a1b38f8dabdaf7eb5ae33276008 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Wed, 1 Jul 2009 20:16:29 -0500 Subject: [PATCH] made stop_requested a global variable The two variables, stop_requested and runner_must_stop were performing the same function, so I am using one variable, stop_requested for this function. --- alsa.c | 9 --------- espeak_sound.c | 5 ----- espeakup.h | 3 +-- softsynth.c | 4 ++-- synth.c | 11 +++++------ 5 files changed, 8 insertions(+), 24 deletions(-) diff --git a/alsa.c b/alsa.c index a45b4f9..adc2ceb 100644 --- a/alsa.c +++ b/alsa.c @@ -35,7 +35,6 @@ #include "espeakup.h" static pthread_mutex_t audio_mutex = PTHREAD_MUTEX_INITIALIZER; -static volatile int stop_requested = 0; static snd_pcm_t *handle; static snd_pcm_hw_params_t *params; @@ -170,16 +169,8 @@ int init_audio(unsigned int rate) void stop_audio(void) { lock_audio_mutex(); - stop_requested = 1; if (snd_pcm_drop(handle) < 0) fprintf(stderr, "Negative return from snd_pcm_drop!\n"); snd_pcm_prepare(handle); unlock_audio_mutex(); } - -void start_audio(void) -{ - lock_audio_mutex(); - stop_requested = 0; - unlock_audio_mutex(); -} diff --git a/espeak_sound.c b/espeak_sound.c index 6101bc8..6e24b8c 100644 --- a/espeak_sound.c +++ b/espeak_sound.c @@ -14,8 +14,3 @@ void stop_audio(void) { return; } - -void start_audio(void) -{ - return; -} diff --git a/espeakup.h b/espeakup.h index b0844a5..3580180 100644 --- a/espeakup.h +++ b/espeakup.h @@ -78,9 +78,8 @@ extern void *softsynth_thread(void *arg); extern void select_audio_mode(void); extern int init_audio(unsigned int rate); extern void stop_audio(void); -extern void start_audio(void); extern volatile int should_run; -extern volatile int runner_must_stop; +extern volatile int stop_requested; extern int self_pipe_fds[2]; #define PIPE_READ_FD (self_pipe_fds[0]) #define PIPE_WRITE_FD (self_pipe_fds[1]) diff --git a/softsynth.c b/softsynth.c index d1f2b34..9747963 100644 --- a/softsynth.c +++ b/softsynth.c @@ -181,9 +181,9 @@ static void process_buffer(struct synth_t *s, char *buf, ssize_t length) static void request_espeak_stop(void) { pthread_mutex_lock(&queue_guard); - runner_must_stop = 1; + stop_requested = 1; pthread_cond_signal(&runner_awake); /* Wake runner, if necessary. */ - while (should_run && (runner_must_stop == 1)) + while (should_run && stop_requested) pthread_cond_wait(&stop_acknowledged, &queue_guard); /* wait for acknowledgement. */ pthread_mutex_unlock(&queue_guard); } diff --git a/synth.c b/synth.c index 734f272..4a987b1 100644 --- a/synth.c +++ b/synth.c @@ -38,7 +38,7 @@ const int rateMultiplier = 34; const int rateOffset = 84; const int volumeMultiplier = 22; -volatile int runner_must_stop = 0; +volatile int stop_requested = 0; static espeak_ERROR set_frequency(struct synth_t *s, int freq, enum adjust_t adj) @@ -134,7 +134,6 @@ static espeak_ERROR stop_speech(void) stop_audio(); rc = espeak_Cancel(); - start_audio(); return rc; } @@ -266,17 +265,17 @@ void *espeak_thread(void *arg) pthread_mutex_lock(&queue_guard); while (should_run) { - while (should_run && !queue_peek(synth_queue) && !runner_must_stop) + while (should_run && !queue_peek(synth_queue) && !stop_requested) pthread_cond_wait(&runner_awake, &queue_guard); - if (runner_must_stop) { + if (stop_requested) { stop_speech(); synth_queue_clear(); - runner_must_stop = 0; + stop_requested = 0; pthread_cond_signal(&stop_acknowledged); } - while (should_run && queue_peek(synth_queue) && !runner_must_stop) { + while (should_run && queue_peek(synth_queue) && !stop_requested) { queue_process_entry(s); pthread_mutex_lock(&queue_guard); }