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.
This commit is contained in:
William Hubbs 2009-07-01 20:16:29 -05:00
commit ac9e12414b
5 changed files with 8 additions and 24 deletions

9
alsa.c
View file

@ -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();
}

View file

@ -14,8 +14,3 @@ void stop_audio(void)
{
return;
}
void start_audio(void)
{
return;
}

View file

@ -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])

View file

@ -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);
}

11
synth.c
View file

@ -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);
}