mirror of
https://github.com/rhasspy/espeak-ng.git
synced 2026-10-31 05:35:35 +00:00
fifo, event: fix thread management
This commit is contained in:
@@ -46,7 +46,7 @@ static bool my_stop_is_acknowledged = false;
|
||||
static bool my_terminate_is_required = 0;
|
||||
// my_thread: polls the audio duration and compares it to the duration of the first event.
|
||||
static pthread_t my_thread;
|
||||
static bool thread_inited;
|
||||
static bool thread_inited = false;
|
||||
|
||||
static t_espeak_callback *my_callback = NULL;
|
||||
static bool my_event_is_running = false;
|
||||
|
||||
+14
-1
@@ -63,6 +63,7 @@ static espeak_ng_STATUS push(t_espeak_command *the_command);
|
||||
static t_espeak_command *pop(void);
|
||||
static void init(int process_parameters);
|
||||
static int node_counter = 0;
|
||||
static bool thread_inited = false;
|
||||
|
||||
enum {
|
||||
MAX_NODE_COUNTER = 400,
|
||||
@@ -89,6 +90,7 @@ void fifo_init()
|
||||
(void *)NULL)) {
|
||||
assert(0);
|
||||
}
|
||||
thread_inited = true;
|
||||
|
||||
pthread_attr_destroy(&a_attrib);
|
||||
|
||||
@@ -131,6 +133,9 @@ espeak_ng_STATUS fifo_add_command(t_espeak_command *the_command)
|
||||
espeak_ng_STATUS fifo_add_commands(t_espeak_command *command1, t_espeak_command *command2)
|
||||
{
|
||||
espeak_ng_STATUS status;
|
||||
if (!thread_inited) {
|
||||
return ENS_NOT_INITIALIZED;
|
||||
}
|
||||
if ((status = pthread_mutex_lock(&my_mutex)) != ENS_OK)
|
||||
return status;
|
||||
|
||||
@@ -166,6 +171,7 @@ espeak_ng_STATUS fifo_add_commands(t_espeak_command *command1, t_espeak_command
|
||||
|
||||
espeak_ng_STATUS fifo_stop()
|
||||
{
|
||||
if (!thread_inited) return ENS_OK;
|
||||
espeak_ng_STATUS status;
|
||||
if ((status = pthread_mutex_lock(&my_mutex)) != ENS_OK)
|
||||
return status;
|
||||
@@ -193,7 +199,11 @@ espeak_ng_STATUS fifo_stop()
|
||||
|
||||
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()
|
||||
@@ -438,12 +448,15 @@ static void init(int process_parameters)
|
||||
|
||||
void fifo_terminate()
|
||||
{
|
||||
if (!thread_inited) return;
|
||||
|
||||
pthread_mutex_lock(&my_mutex);
|
||||
my_terminate_is_required = true;
|
||||
pthread_mutex_unlock(&my_mutex);
|
||||
pthread_cond_signal(&my_cond_start_is_required);
|
||||
pthread_join(my_thread, NULL);
|
||||
my_terminate_is_required = false;
|
||||
thread_inited = false;
|
||||
|
||||
pthread_mutex_destroy(&my_mutex);
|
||||
pthread_cond_destroy(&my_cond_start_is_required);
|
||||
|
||||
@@ -273,6 +273,9 @@ ESPEAK_NG_API espeak_ng_STATUS espeak_ng_InitializeOutput(espeak_ng_OUTPUT_MODE
|
||||
my_audio = create_audio_device_object(device, "eSpeak", "Text-to-Speech");
|
||||
#endif
|
||||
|
||||
#if USE_ASYNC
|
||||
if ((my_mode & ENOUTPUT_MODE_SYNCHRONOUS) == 0) fifo_init();
|
||||
#endif
|
||||
|
||||
// Don't allow buffer be smaller than safe minimum
|
||||
if (buffer_length < min_buffer_length)
|
||||
@@ -393,10 +396,6 @@ ESPEAK_NG_API espeak_ng_STATUS espeak_ng_Initialize(espeak_ng_ERROR_CONTEXT *con
|
||||
SetParameter(espeakPUNCTUATION, option_punctuation, 0);
|
||||
SetParameter(espeakWORDGAP, 0, 0);
|
||||
|
||||
#if USE_ASYNC
|
||||
fifo_init();
|
||||
#endif
|
||||
|
||||
option_phonemes = 0;
|
||||
option_phoneme_events = 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user