[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] Remove the module_semaphore_init() function, and other changes a
From: |
sub |
Subject: |
[PATCH] Remove the module_semaphore_init() function, and other changes associated with this |
Date: |
Sat, 10 Dec 2011 05:49:49 +0400 |
In accordance with the remarks of Trev
(see http://lists.freebsoft.org/pipermail/speechd/2011q4/004301.html):
sem_t* is replaced by sem_t (for the modules that use semaphores).
module_semaphore_init() is replaced by the direct call of sem_init().
Add sem_destroy calls in module_close() (for all modules, excluding espeak.c).
Change a first argument for all cem_... calls.
Remove declaration and definition of module_semaphore_init() from module_utils.
---
src/modules/cicero.c | 17 ++++++++---
src/modules/dummy.c | 16 ++++++++--
src/modules/espeak.c | 44 +++++++++++++++++++----------
src/modules/festival.c | 17 +++++++----
src/modules/flite.c | 15 +++++++--
src/modules/generic.c | 17 ++++++++--
src/modules/ibmtts.c | 66 ++++++++++++++++++++++++++++++--------------
src/modules/ivona.c | 17 ++++++++---
src/modules/module_utils.c | 17 -----------
src/modules/module_utils.h | 1 -
src/modules/pico.c | 43 ++++++++++++++++------------
11 files changed, 169 insertions(+), 101 deletions(-)
diff --git a/src/modules/cicero.c b/src/modules/cicero.c
index 1ad1b8f..821e4d6 100644
--- a/src/modules/cicero.c
+++ b/src/modules/cicero.c
@@ -44,7 +44,7 @@ DECLARE_DEBUG()
static int cicero_speaking = 0;
static pthread_t cicero_speaking_thread;
-static sem_t *cicero_semaphore;
+static sem_t cicero_semaphore;
static char **cicero_message;
static SPDMessageType cicero_message_type;
@@ -205,7 +205,13 @@ int module_init(char **status_info)
cicero_message = g_malloc(sizeof(char *));
*cicero_message = NULL;
- cicero_semaphore = module_semaphore_init();
+ if (0 != sem_init(&cicero_semaphore , 0, 0))
+ {
+ *status_info = g_strdup(MODULE_NAME
+ ": Semaphore initialization failed.");
+ DBG(*status_info);
+ return -1;
+ }
DBG("Cicero: creating new thread for cicero_tracking\n");
cicero_speaking = 0;
@@ -257,7 +263,7 @@ int module_speak(gchar * data, size_t bytes, SPDMessageType
msgtype)
/* Send semaphore signal to the speaking thread */
cicero_speaking = 1;
- sem_post(cicero_semaphore);
+ sem_post(&cicero_semaphore);
DBG("Cicero: leaving module_speak() normaly\n\r");
return bytes;
@@ -295,7 +301,8 @@ int module_close(void)
if (module_terminate_thread(cicero_speaking_thread) != 0)
return -1;
-
+
+ sem_destroy(&cicero_semaphore );
return 0;
}
@@ -314,7 +321,7 @@ void *_cicero_speak(void *nothing)
DBG("cicero: speaking thread starting.......\n");
set_speaking_thread_parameters();
while (1) {
- sem_wait(cicero_semaphore);
+ sem_wait(&cicero_semaphore);
DBG("Semaphore on\n");
len = strlen(*cicero_message);
cicero_stop = 0;
diff --git a/src/modules/dummy.c b/src/modules/dummy.c
index 056e2a9..b8312b7 100644
--- a/src/modules/dummy.c
+++ b/src/modules/dummy.c
@@ -45,7 +45,7 @@ static int dummy_speaking = 0;
static pthread_t dummy_speak_thread;
static pid_t dummy_pid;
-static sem_t *dummy_semaphore;
+static sem_t dummy_semaphore;
/* Internal functions prototypes */
static void *_dummy_speak(void *);
@@ -68,7 +68,13 @@ int module_init(char **status_info)
*status_info = NULL;
- dummy_semaphore = module_semaphore_init();
+ if (0 != sem_init(&dummy_semaphore, 0, 0))
+ {
+ *status_info = g_strdup(MODULE_NAME
+ ": Semaphore initialization failed.");
+ DBG(*status_info);
+ return -1;
+ }
DBG("Dummy: creating new thread for dummy_speak\n");
dummy_speaking = 0;
@@ -108,7 +114,7 @@ int module_speak(gchar * data, size_t bytes, SPDMessageType
msgtype)
/* Send semaphore signal to the speaking thread */
dummy_speaking = 1;
- sem_post(dummy_semaphore);
+ sem_post(&dummy_semaphore);
DBG("Dummy: leaving write() normaly\n\r");
return bytes;
@@ -153,6 +159,8 @@ int module_close(void)
if (module_terminate_thread(dummy_speak_thread) != 0)
return -1;
+
+ sem_destroy(&dummy_semaphore );
return 0;
}
@@ -168,7 +176,7 @@ void *_dummy_speak(void *nothing)
set_speaking_thread_parameters();
while (1) {
- sem_wait(dummy_semaphore);
+ sem_wait(&dummy_semaphore);
DBG("Semaphore on\n");
module_report_event_begin();
diff --git a/src/modules/espeak.c b/src/modules/espeak.c
index dab8ce3..7e5f302 100644
--- a/src/modules/espeak.c
+++ b/src/modules/espeak.c
@@ -87,9 +87,9 @@ static pthread_mutex_t espeak_state_mutex;
static pthread_t espeak_play_thread;
static pthread_t espeak_stop_or_pause_thread;
-static sem_t *espeak_stop_or_pause_semaphore;
+static sem_t espeak_stop_or_pause_semaphore;
static pthread_mutex_t espeak_stop_or_pause_suspended_mutex;
-static sem_t *espeak_play_semaphore;
+static sem_t espeak_play_semaphore;
static pthread_mutex_t espeak_play_suspended_mutex;
static gboolean espeak_close_requested = FALSE;
@@ -292,7 +292,14 @@ int module_init(char **status_info)
pthread_mutex_init(&espeak_state_mutex, NULL);
DBG("Espeak: Creating new thread for stop or pause.");
- espeak_stop_or_pause_semaphore = module_semaphore_init();
+ if (0 != sem_init(&espeak_stop_or_pause_semaphore, 0, 0))
+ {
+ *status_info = g_strdup(MODULE_NAME
+ ": Semaphore initialization failed.");
+ DBG(*status_info);
+ return FATAL_ERROR;
+ }
+
ret =
pthread_create(&espeak_stop_or_pause_thread, NULL,
_espeak_stop_or_pause, NULL);
@@ -303,7 +310,14 @@ int module_init(char **status_info)
return FATAL_ERROR;
}
- espeak_play_semaphore = module_semaphore_init();
+ if (0 != sem_init(&espeak_play_semaphore, 0, 0))
+ {
+ *status_info = g_strdup(MODULE_NAME
+ ": Semaphore initialization failed.");
+ DBG(*status_info);
+ return FATAL_ERROR;
+ }
+
DBG("Espeak: Creating new thread for playback.");
ret = pthread_create(&espeak_play_thread, NULL, _espeak_play, NULL);
if (ret != OK) {
@@ -443,7 +457,7 @@ int module_stop(void)
DBG("Espeak: stopping...");
espeak_stop_requested = TRUE;
/* Wake the stop_or_pause thread. */
- sem_post(espeak_stop_or_pause_semaphore);
+ sem_post(&espeak_stop_or_pause_semaphore);
} else {
DBG("Espeak: Cannot stop now.");
}
@@ -476,8 +490,8 @@ int module_close(void)
pthread_cond_broadcast(&playback_queue_condition);
pthread_mutex_unlock(&playback_queue_mutex);
- sem_post(espeak_play_semaphore);
- sem_post(espeak_stop_or_pause_semaphore);
+ sem_post(&espeak_play_semaphore);
+ sem_post(&espeak_stop_or_pause_semaphore);
/* Give threads a chance to quit on their own terms. */
g_usleep(25000);
@@ -502,8 +516,8 @@ int module_close(void)
pthread_mutex_destroy(&espeak_stop_or_pause_suspended_mutex);
pthread_mutex_destroy(&playback_queue_mutex);
pthread_cond_destroy(&playback_queue_condition);
- sem_destroy(espeak_play_semaphore);
- sem_destroy(espeak_stop_or_pause_semaphore);
+ sem_destroy(&espeak_play_semaphore);
+ sem_destroy(&espeak_stop_or_pause_semaphore);
return 0;
}
@@ -540,10 +554,10 @@ static void *_espeak_stop_or_pause(void *nothing)
while (!espeak_close_requested) {
/* If semaphore not set, set suspended lock and suspend until it is
signaled. */
- if (0 != sem_trywait(espeak_stop_or_pause_semaphore)) {
+ if (0 != sem_trywait(&espeak_stop_or_pause_semaphore)) {
pthread_mutex_lock
(&espeak_stop_or_pause_suspended_mutex);
- sem_wait(espeak_stop_or_pause_semaphore);
+ sem_wait(&espeak_stop_or_pause_semaphore);
pthread_mutex_unlock
(&espeak_stop_or_pause_suspended_mutex);
}
@@ -804,7 +818,7 @@ static int synth_callback(short *wav, int numsamples,
espeak_EVENT * events)
espeak_state = BEFORE_PLAY;
espeak_add_flag_to_playback_queue(ESPEAK_QET_BEGIN);
/* Wake up playback thread */
- sem_post(espeak_play_semaphore);
+ sem_post(&espeak_play_semaphore);
}
pthread_mutex_unlock(&espeak_state_mutex);
@@ -1041,9 +1055,9 @@ static void *_espeak_play(void *nothing)
while (!espeak_close_requested) {
/* If semaphore not set, set suspended lock and suspend until it is
signaled. */
- if (0 != sem_trywait(espeak_play_semaphore)) {
+ if (0 != sem_trywait(&espeak_play_semaphore)) {
pthread_mutex_lock(&espeak_play_suspended_mutex);
- sem_wait(espeak_play_semaphore);
+ sem_wait(&espeak_play_semaphore);
pthread_mutex_unlock(&espeak_play_suspended_mutex);
}
DBG("Espeak: Playback semaphore on.");
@@ -1086,7 +1100,7 @@ static void *_espeak_play(void *nothing)
espeak_pause_state =
ESPEAK_PAUSE_MARK_REPORTED;
sem_post
- (espeak_stop_or_pause_semaphore);
+ (&espeak_stop_or_pause_semaphore);
finished = TRUE;
}
pthread_mutex_unlock(&espeak_state_mutex);
diff --git a/src/modules/festival.c b/src/modules/festival.c
index 6264108..ff16dfb 100644
--- a/src/modules/festival.c
+++ b/src/modules/festival.c
@@ -40,7 +40,7 @@ DECLARE_DEBUG()
/* Thread and process control */
static pthread_t festival_speak_thread;
-static sem_t *festival_semaphore;
+static sem_t festival_semaphore;
static int festival_speaking = 0;
static int festival_pause_requested = 0;
@@ -285,9 +285,13 @@ int module_init(char **status_info)
/* Initialize festival_speak thread to handle communication
with festival in a separate thread (to be faster in communication
with Speech Dispatcher) */
- festival_semaphore = module_semaphore_init();
- if (festival_semaphore == NULL)
+ if (0 != sem_init(&festival_semaphore, 0, 0))
+ {
+ *status_info = g_strdup(MODULE_NAME
+ ": Semaphore initialization failed.");
+ DBG(*status_info);
return -1;
+ }
DBG("Festival: creating new thread for festival_speak\n");
festival_speaking = 0;
ret =
@@ -398,7 +402,7 @@ int module_speak(char *data, size_t bytes, SPDMessageType
msgtype)
/* Send semaphore signal to the speaking thread */
festival_speaking = 1;
- sem_post(festival_semaphore);
+ sem_post(&festival_semaphore);
DBG("Festival: leaving write() normaly\n\r");
return bytes;
@@ -476,7 +480,8 @@ int module_close(void)
/* TODO: Solve this */
// DBG("Removing junk files in tmp/");
// system("rm -f /tmp/est* 2> /dev/null");
-
+
+ sem_destroy(&festival_semaphore);
return 0;
}
@@ -611,7 +616,7 @@ void *_festival_speak(void *nothing)
while (1) {
sem_wait:
- sem_wait(festival_semaphore);
+ sem_wait(&festival_semaphore);
DBG("Semaphore on, speaking\n");
festival_stop = 0;
diff --git a/src/modules/flite.c b/src/modules/flite.c
index 1619e9c..dad3d6a 100644
--- a/src/modules/flite.c
+++ b/src/modules/flite.c
@@ -43,7 +43,7 @@ DECLARE_DEBUG();
static int flite_speaking = 0;
static pthread_t flite_speak_thread;
-static sem_t *flite_semaphore;
+static sem_t flite_semaphore;
static char **flite_message;
static SPDMessageType flite_message_type;
@@ -125,7 +125,13 @@ int module_init(char **status_info)
flite_message = g_malloc(sizeof(char *));
*flite_message = NULL;
- flite_semaphore = module_semaphore_init();
+ if (0 != sem_init(&flite_semaphore, 0, 0))
+ {
+ *status_info = g_strdup(MODULE_NAME
+ ": Semaphore initialization failed.");
+ DBG(*status_info);
+ return -1;
+ }
DBG("Flite: creating new thread for flite_speak\n");
flite_speaking = 0;
@@ -177,7 +183,7 @@ int module_speak(gchar * data, size_t bytes, SPDMessageType
msgtype)
/* Send semaphore signal to the speaking thread */
flite_speaking = 1;
- sem_post(flite_semaphore);
+ sem_post(&flite_semaphore);
DBG("Flite: leaving write() normally\n\r");
return bytes;
@@ -229,6 +235,7 @@ int module_close(void)
return -1;
g_free(flite_voice);
+ sem_destroy(&flite_semaphore);
return 0;
}
@@ -273,7 +280,7 @@ void *_flite_speak(void *nothing)
set_speaking_thread_parameters();
while (1) {
- sem_wait(flite_semaphore);
+ sem_wait(&flite_semaphore);
DBG("Semaphore on\n");
flite_stop = 0;
diff --git a/src/modules/generic.c b/src/modules/generic.c
index 8639f80..1a22e7a 100644
--- a/src/modules/generic.c
+++ b/src/modules/generic.c
@@ -42,7 +42,7 @@ static int generic_speaking = 0;
static pthread_t generic_speak_thread;
static pid_t generic_pid;
-static sem_t *generic_semaphore;
+static sem_t generic_semaphore;
static char **generic_message;
static SPDMessageType generic_message_type;
@@ -149,7 +149,14 @@ int module_init(char **status_info)
generic_msg_language->name = g_strdup("english");
generic_message = g_malloc(sizeof(char *));
- generic_semaphore = module_semaphore_init();
+
+ if (0 != sem_init(&generic_semaphore, 0, 0))
+ {
+ *status_info = g_strdup(MODULE_NAME
+ ": Semaphore initialization failed.");
+ DBG(*status_info);
+ return -1;
+ }
DBG("Generic: creating new thread for generic_speak\n");
generic_speaking = 0;
@@ -227,7 +234,7 @@ int module_speak(gchar * data, size_t bytes, SPDMessageType
msgtype)
/* Send semaphore signal to the speaking thread */
generic_speaking = 1;
- sem_post(generic_semaphore);
+ sem_post(&generic_semaphore);
DBG("Generic: leaving write() normaly\n\r");
return bytes;
@@ -273,6 +280,8 @@ int module_close(void)
if (module_terminate_thread(generic_speak_thread) != 0)
return -1;
+
+ sem_destroy(&generic_semaphore);
return 0;
}
@@ -320,7 +329,7 @@ void *_generic_speak(void *nothing)
set_speaking_thread_parameters();
while (1) {
- sem_wait(generic_semaphore);
+ sem_wait(&generic_semaphore);
DBG("Semaphore on\n");
ret = pipe(module_pipe.pc);
diff --git a/src/modules/ibmtts.c b/src/modules/ibmtts.c
index 1adfbb1..d11f5be 100644
--- a/src/modules/ibmtts.c
+++ b/src/modules/ibmtts.c
@@ -160,9 +160,9 @@ static pthread_t ibmtts_synth_thread;
static pthread_t ibmtts_play_thread;
static pthread_t ibmtts_stop_or_pause_thread;
-static sem_t *ibmtts_synth_semaphore;
-static sem_t *ibmtts_play_semaphore;
-static sem_t *ibmtts_stop_or_pause_semaphore;
+static sem_t ibmtts_synth_semaphore;
+static sem_t ibmtts_play_semaphore;
+static sem_t ibmtts_stop_or_pause_semaphore;
static pthread_mutex_t ibmtts_synth_suspended_mutex;
static pthread_mutex_t ibmtts_play_suspended_mutex;
@@ -493,7 +493,14 @@ int module_init(char **status_info)
*ibmtts_message = NULL;
DBG("Ibmtts: Creating new thread for stop or pause.");
- ibmtts_stop_or_pause_semaphore = module_semaphore_init();
+ if (0 != sem_init(&ibmtts_stop_or_pause_semaphore, 0, 0))
+ {
+ *status_info = g_strdup(MODULE_NAME
+ ": Semaphore initialization failed.");
+ DBG(*status_info);
+ return FATAL_ERROR;
+ }
+
ret =
pthread_create(&ibmtts_stop_or_pause_thread, NULL,
_ibmtts_stop_or_pause, NULL);
@@ -509,7 +516,14 @@ int module_init(char **status_info)
}
DBG("Ibmtts: Creating new thread for playback.");
- ibmtts_play_semaphore = module_semaphore_init();
+ if (0 != sem_init(&ibmtts_play_semaphore, 0, 0))
+ {
+ *status_info = g_strdup(MODULE_NAME
+ ": Semaphore initialization failed.");
+ DBG(*status_info);
+ return FATAL_ERROR;
+ }
+
ret = pthread_create(&ibmtts_play_thread, NULL, _ibmtts_play, NULL);
if (0 != ret) {
DBG("Ibmtts: play thread creation failed.");
@@ -522,7 +536,14 @@ int module_init(char **status_info)
}
DBG("Ibmtts: Creating new thread for IBM TTS synthesis.");
- ibmtts_synth_semaphore = module_semaphore_init();
+ if (0 != sem_init(&ibmtts_synth_semaphore, 0, 0))
+ {
+ *status_info = g_strdup(MODULE_NAME
+ ": Semaphore initialization failed.");
+ DBG(*status_info);
+ return FATAL_ERROR;
+ }
+
ret = pthread_create(&ibmtts_synth_thread, NULL, _ibmtts_synth, NULL);
if (0 != ret) {
DBG("Ibmtts: synthesis thread creation failed.");
@@ -611,7 +632,7 @@ int module_speak(gchar * data, size_t bytes, SPDMessageType
msgtype)
}
/* Send semaphore signal to the synthesis thread */
- sem_post(ibmtts_synth_semaphore);
+ sem_post(&ibmtts_synth_semaphore);
DBG("Ibmtts: Leaving module_speak() normally.");
return TRUE;
@@ -631,7 +652,7 @@ int module_stop(void)
ibmtts_stop_play_requested = IBMTTS_TRUE;
/* Wake the stop_or_pause thread. */
- sem_post(ibmtts_stop_or_pause_semaphore);
+ sem_post(&ibmtts_stop_or_pause_semaphore);
}
return OK;
@@ -653,7 +674,7 @@ size_t module_pause(void)
ibmtts_pause_requested = IBMTTS_TRUE;
/* Wake the stop_or_pause thread. */
- sem_post(ibmtts_stop_or_pause_semaphore);
+ sem_post(&ibmtts_stop_or_pause_semaphore);
return OK;
}
@@ -682,9 +703,9 @@ int module_close(void)
/* Request each thread exit and wait until it exits. */
DBG("Ibmtts: Terminating threads");
ibmtts_thread_exit_requested = IBMTTS_TRUE;
- sem_post(ibmtts_synth_semaphore);
- sem_post(ibmtts_play_semaphore);
- sem_post(ibmtts_stop_or_pause_semaphore);
+ sem_post(&ibmtts_synth_semaphore);
+ sem_post(&ibmtts_play_semaphore);
+ sem_post(&ibmtts_stop_or_pause_semaphore);
if (0 != pthread_join(ibmtts_synth_thread, NULL))
return -1;
if (0 != pthread_join(ibmtts_play_thread, NULL))
@@ -701,6 +722,9 @@ int module_close(void)
}
free_voice_list();
+ sem_destroy(&ibmtts_synth_semaphore);
+ sem_destroy(&ibmtts_play_semaphore);
+ sem_destroy(&ibmtts_stop_or_pause_semaphore);
return 0;
}
@@ -773,10 +797,10 @@ static void *_ibmtts_stop_or_pause(void *nothing)
while (!ibmtts_thread_exit_requested) {
/* If semaphore not set, set suspended lock and suspend until it is
signaled. */
- if (0 != sem_trywait(ibmtts_stop_or_pause_semaphore)) {
+ if (0 != sem_trywait(&ibmtts_stop_or_pause_semaphore)) {
pthread_mutex_lock
(&ibmtts_stop_or_pause_suspended_mutex);
- sem_wait(ibmtts_stop_or_pause_semaphore);
+ sem_wait(&ibmtts_stop_or_pause_semaphore);
pthread_mutex_unlock
(&ibmtts_stop_or_pause_suspended_mutex);
if (ibmtts_thread_exit_requested)
@@ -917,9 +941,9 @@ static void *_ibmtts_synth(void *nothing)
while (!ibmtts_thread_exit_requested) {
/* If semaphore not set, set suspended lock and suspend until it is
signaled. */
- if (0 != sem_trywait(ibmtts_synth_semaphore)) {
+ if (0 != sem_trywait(&ibmtts_synth_semaphore)) {
pthread_mutex_lock(&ibmtts_synth_suspended_mutex);
- sem_wait(ibmtts_synth_semaphore);
+ sem_wait(&ibmtts_synth_semaphore);
pthread_mutex_unlock(&ibmtts_synth_suspended_mutex);
if (ibmtts_thread_exit_requested)
break;
@@ -955,7 +979,7 @@ static void *_ibmtts_synth(void *nothing)
/* Wake up the audio playback thread, if not already awake. */
if (!is_thread_busy
(&ibmtts_play_suspended_mutex))
- sem_post(ibmtts_play_semaphore);
+ sem_post(&ibmtts_play_semaphore);
continue;
} else
eciSetParam(eciHandle, eciTextMode,
@@ -1367,7 +1391,7 @@ static enum ECICallbackReturn eciCallback(ECIHand hEngine,
ret = ibmtts_add_audio_to_playback_queue(audio_chunk, lparam);
/* Wake up the audio playback thread, if not already awake. */
if (!is_thread_busy(&ibmtts_play_suspended_mutex))
- sem_post(ibmtts_play_semaphore);
+ sem_post(&ibmtts_play_semaphore);
return eciDataProcessed;
break;
case eciIndexReply:
@@ -1380,7 +1404,7 @@ static enum ECICallbackReturn eciCallback(ECIHand hEngine,
}
/* Wake up the audio playback thread, if not already awake. */
if (!is_thread_busy(&ibmtts_play_suspended_mutex))
- sem_post(ibmtts_play_semaphore);
+ sem_post(&ibmtts_play_semaphore);
return eciDataProcessed;
break;
default:
@@ -1532,9 +1556,9 @@ static void *_ibmtts_play(void *nothing)
while (!ibmtts_thread_exit_requested) {
/* If semaphore not set, set suspended lock and suspend until it is
signaled. */
- if (0 != sem_trywait(ibmtts_play_semaphore)) {
+ if (0 != sem_trywait(&ibmtts_play_semaphore)) {
pthread_mutex_lock(&ibmtts_play_suspended_mutex);
- sem_wait(ibmtts_play_semaphore);
+ sem_wait(&ibmtts_play_semaphore);
pthread_mutex_unlock(&ibmtts_play_suspended_mutex);
}
/* DBG("Ibmtts: Playback semaphore on."); */
diff --git a/src/modules/ivona.c b/src/modules/ivona.c
index a4050ff..3f81cff 100644
--- a/src/modules/ivona.c
+++ b/src/modules/ivona.c
@@ -51,7 +51,7 @@ DECLARE_DEBUG();
static int ivona_speaking = 0;
static pthread_t ivona_speak_thread;
-static sem_t *ivona_semaphore;
+static sem_t ivona_semaphore;
static char **ivona_message;
static SPDMessageType ivona_message_type;
@@ -145,7 +145,13 @@ module_init(char **status_info)
ivona_message = g_malloc (sizeof (char*));
*ivona_message = NULL;
- ivona_semaphore = module_semaphore_init();
+ if (0 != sem_init(&ivona_semaphore, 0, 0))
+ {
+ *status_info = g_strdup(MODULE_NAME
+ ": Semaphore initialization failed.");
+ DBG(*status_info);
+ return -1;
+ }
DBG("Ivona: creating new thread for ivona_speak\n");
ivona_speaking = 0;
@@ -204,7 +210,7 @@ module_speak(gchar *data, size_t bytes, SPDMessageType
msgtype)
/* Send semaphore signal to the speaking thread */
ivona_speaking = 1;
- sem_post(ivona_semaphore);
+ sem_post(&ivona_semaphore);
DBG("Ivona: leaving write() normally\n\r");
return bytes;
@@ -255,7 +261,8 @@ module_close(void)
DBG("Terminating threads");
if (module_terminate_thread(ivona_speak_thread) != 0)
return -1;
-
+
+ sem_destroy(&ivona_semaphore);
return 0;
}
@@ -423,7 +430,7 @@ _ivona_speak(void* nothing)
set_speaking_thread_parameters();
while(1){
- sem_wait(ivona_semaphore);
+ sem_wait(&ivona_semaphore);
DBG("Semaphore on\n");
ivona_stop = 0;
diff --git a/src/modules/module_utils.c b/src/modules/module_utils.c
index a4c187a..de81c79 100644
--- a/src/modules/module_utils.c
+++ b/src/modules/module_utils.c
@@ -909,23 +909,6 @@ module_terminate_thread(pthread_t thread)
return 0;
}
-sem_t*
-module_semaphore_init()
-{
- sem_t *semaphore;
- int ret;
-
- semaphore = (sem_t *) g_malloc(sizeof(sem_t));
- if (semaphore == NULL) return NULL;
- ret = sem_init(semaphore, 0, 0);
- if (ret != 0){
- DBG("Semaphore initialization failed");
- g_free(semaphore);
- semaphore = NULL;
- }
- return semaphore;
-}
-
char *
module_recode_to_iso(char *data, int bytes, char *language, char *fallback)
{
diff --git a/src/modules/module_utils.h b/src/modules/module_utils.h
index 45a975f..031692f 100644
--- a/src/modules/module_utils.h
+++ b/src/modules/module_utils.h
@@ -225,7 +225,6 @@ int module_parent_wait_continue(TModuleDoublePipe dpipe);
void set_speaking_thread_parameters();
int module_terminate_thread(pthread_t thread);
-sem_t *module_semaphore_init();
char *module_recode_to_iso(char *data, int bytes, char *language,
char *fallback);
void module_signal_end(void);
diff --git a/src/modules/pico.c b/src/modules/pico.c
index 2e72e12..2b49da8 100644
--- a/src/modules/pico.c
+++ b/src/modules/pico.c
@@ -106,8 +106,8 @@ static const SPDVoice *pico_voices_list[] = {
};
static GThread *pico_play_thread;
-static sem_t *pico_play_semaphore;
-static sem_t *pico_idle_semaphore;
+static sem_t pico_play_semaphore;
+static sem_t pico_idle_semaphore;
enum states { STATE_IDLE, STATE_PLAY, STATE_PAUSE, STATE_STOP, STATE_CLOSE };
static enum states pico_state;
@@ -246,7 +246,7 @@ static gpointer pico_play_func(gpointer nothing)
while (g_atomic_int_get(&pico_state) != STATE_CLOSE) {
- sem_wait(pico_play_semaphore);
+ sem_wait(&pico_play_semaphore);
if (g_atomic_int_get(&pico_state) != STATE_PLAY)
continue;
@@ -265,14 +265,14 @@ static gpointer pico_play_func(gpointer nothing)
if (g_atomic_int_get(&pico_state) == STATE_STOP) {
module_report_event_stop();
g_atomic_int_set(&pico_state, STATE_IDLE);
- sem_post(pico_idle_semaphore);
+ sem_post(&pico_idle_semaphore);
}
if (g_atomic_int_get(&pico_state) == STATE_PAUSE) {
module_report_event_pause();
g_atomic_int_set(&pico_state, STATE_IDLE);
- sem_post(pico_idle_semaphore);
+ sem_post(&pico_idle_semaphore);
}
DBG(MODULE_NAME ": state %d", pico_state);
@@ -397,12 +397,19 @@ int module_init(char **status_info)
if (!g_thread_supported())
g_thread_init(NULL);
- pico_play_semaphore = module_semaphore_init();
- pico_idle_semaphore = module_semaphore_init();
- if (pico_play_semaphore == NULL || pico_idle_semaphore == NULL) {
- *status_info = g_strdup_printf(MODULE_NAME
- "Failed to initialize semaphores!");
- DBG(MODULE_NAME ": %s", *status_info);
+ if (0 != sem_init(&pico_play_semaphore, 0, 0))
+ {
+ *status_info = g_strdup(MODULE_NAME
+ ": Semaphore initialization failed.");
+ DBG(*status_info);
+ return -1;
+ }
+
+ if (0 != sem_init(&pico_idle_semaphore, 0, 0))
+ {
+ *status_info = g_strdup(MODULE_NAME
+ ": Semaphore initialization failed.");
+ DBG(*status_info);
return -1;
}
@@ -558,7 +565,7 @@ int module_speak(char *data, size_t bytes, SPDMessageType
msgtype)
}
*/
g_atomic_int_set(&pico_state, STATE_PLAY);
- sem_post(pico_play_semaphore);
+ sem_post(&pico_play_semaphore);
return bytes;
}
@@ -573,7 +580,7 @@ int module_stop(void)
}
g_atomic_int_set(&pico_state, STATE_STOP);
- sem_wait(pico_idle_semaphore);
+ sem_wait(&pico_idle_semaphore);
/* reset Pico engine. */
if ((ret = pico_resetEngine(picoEngine, PICO_RESET_SOFT))) {
@@ -597,7 +604,7 @@ size_t module_pause(void)
}
g_atomic_int_set(&pico_state, STATE_PAUSE);
- sem_wait(pico_idle_semaphore);
+ sem_wait(&pico_idle_semaphore);
/* reset Pico engine. */
if ((ret = pico_resetEngine(picoEngine, PICO_RESET_SOFT))) {
@@ -614,7 +621,7 @@ int module_close(void)
{
g_atomic_int_set(&pico_state, STATE_CLOSE);
- sem_post(pico_play_semaphore);
+ sem_post(&pico_play_semaphore);
g_thread_join(pico_play_thread);
@@ -623,10 +630,8 @@ int module_close(void)
picoSystem = NULL;
}
- g_free(pico_idle_semaphore);
- g_free(pico_play_semaphore);
- pico_idle_semaphore = NULL;
- pico_play_semaphore = NULL;
+ sem_destroy(&pico_idle_semaphore);
+ sem_destroy(&pico_play_semaphore);
return 0;
}
--
1.7.4.1
- [PATCH] Remove the module_semaphore_init() function, and other changes associated with this ,
sub <=