Browse Source

fifo, event: fix thread management

master
Yury Popov 2 years ago
parent
commit
820b85ed21
No account linked to committer's email address
3 changed files with 18 additions and 6 deletions
  1. 1
    1
      src/libespeak-ng/event.c
  2. 14
    1
      src/libespeak-ng/fifo.c
  3. 3
    4
      src/libespeak-ng/speech.c

+ 1
- 1
src/libespeak-ng/event.c View File

static bool my_terminate_is_required = 0; static bool my_terminate_is_required = 0;
// my_thread: polls the audio duration and compares it to the duration of the first event. // my_thread: polls the audio duration and compares it to the duration of the first event.
static pthread_t my_thread; static pthread_t my_thread;
static bool thread_inited;
static bool thread_inited = false;


static t_espeak_callback *my_callback = NULL; static t_espeak_callback *my_callback = NULL;
static bool my_event_is_running = false; static bool my_event_is_running = false;

+ 14
- 1
src/libespeak-ng/fifo.c View File

static t_espeak_command *pop(void); static t_espeak_command *pop(void);
static void init(int process_parameters); static void init(int process_parameters);
static int node_counter = 0; static int node_counter = 0;
static bool thread_inited = false;


enum { enum {
MAX_NODE_COUNTER = 400, MAX_NODE_COUNTER = 400,
(void *)NULL)) { (void *)NULL)) {
assert(0); assert(0);
} }
thread_inited = true;


pthread_attr_destroy(&a_attrib); pthread_attr_destroy(&a_attrib);


espeak_ng_STATUS fifo_add_commands(t_espeak_command *command1, t_espeak_command *command2) espeak_ng_STATUS fifo_add_commands(t_espeak_command *command1, t_espeak_command *command2)
{ {
espeak_ng_STATUS status; espeak_ng_STATUS status;
if (!thread_inited) {
return ENS_NOT_INITIALIZED;
}
if ((status = pthread_mutex_lock(&my_mutex)) != ENS_OK) if ((status = pthread_mutex_lock(&my_mutex)) != ENS_OK)
return status; return status;




espeak_ng_STATUS fifo_stop() espeak_ng_STATUS fifo_stop()
{ {
if (!thread_inited) return ENS_OK;
espeak_ng_STATUS status; espeak_ng_STATUS status;
if ((status = pthread_mutex_lock(&my_mutex)) != ENS_OK) if ((status = pthread_mutex_lock(&my_mutex)) != ENS_OK)
return status; return status;


int fifo_is_busy() int fifo_is_busy()
{ {
return my_command_is_running;
if (!thread_inited) return false;
pthread_mutex_lock(&my_mutex);
bool running = my_command_is_running;
pthread_mutex_unlock(&my_mutex);
return running;
} }


static int sleep_until_start_request_or_inactivity() static int sleep_until_start_request_or_inactivity()


void fifo_terminate() void fifo_terminate()
{ {
if (!thread_inited) return;

pthread_mutex_lock(&my_mutex); pthread_mutex_lock(&my_mutex);
my_terminate_is_required = true; my_terminate_is_required = true;
pthread_mutex_unlock(&my_mutex); pthread_mutex_unlock(&my_mutex);
pthread_cond_signal(&my_cond_start_is_required); pthread_cond_signal(&my_cond_start_is_required);
pthread_join(my_thread, NULL); pthread_join(my_thread, NULL);
my_terminate_is_required = false; my_terminate_is_required = false;
thread_inited = false;


pthread_mutex_destroy(&my_mutex); pthread_mutex_destroy(&my_mutex);
pthread_cond_destroy(&my_cond_start_is_required); pthread_cond_destroy(&my_cond_start_is_required);

+ 3
- 4
src/libespeak-ng/speech.c View File

my_audio = create_audio_device_object(device, "eSpeak", "Text-to-Speech"); my_audio = create_audio_device_object(device, "eSpeak", "Text-to-Speech");
#endif #endif


#if USE_ASYNC
if ((my_mode & ENOUTPUT_MODE_SYNCHRONOUS) == 0) fifo_init();
#endif


// Don't allow buffer be smaller than safe minimum // Don't allow buffer be smaller than safe minimum
if (buffer_length < min_buffer_length) if (buffer_length < min_buffer_length)
SetParameter(espeakPUNCTUATION, option_punctuation, 0); SetParameter(espeakPUNCTUATION, option_punctuation, 0);
SetParameter(espeakWORDGAP, 0, 0); SetParameter(espeakWORDGAP, 0, 0);


#if USE_ASYNC
fifo_init();
#endif

option_phonemes = 0; option_phonemes = 0;
option_phoneme_events = 0; option_phoneme_events = 0;



Loading…
Cancel
Save