speechd-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Remove the module_semaphore_init() function, and other chang


From: sub
Subject: Re: [PATCH] Remove the module_semaphore_init() function, and other changes associated with this 
Date: Mon, 12 Dec 2011 08:05:55 +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 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).
 Modify a first argument for all cem_... calls.
 Remove declaration and definition of module_semaphore_init() 
 from module_utils.
 Add #include <semaphore.h> to each module file which uses sem_...() 
calls(excluding pico.c).

---
 src/modules/cicero.c       |   14 +++++++-----
 src/modules/dummy.c        |   13 +++++++----
 src/modules/espeak.c       |   33 ++++++++++++++++-------------
 src/modules/festival.c     |   16 ++++++++------
 src/modules/flite.c        |   13 +++++++----
 src/modules/generic.c      |   14 ++++++++----
 src/modules/ibmtts.c       |   49 +++++++++++++++++++++++++------------------
 src/modules/ivona.c        |   15 ++++++++-----
 src/modules/module_utils.c |   17 ---------------
 src/modules/module_utils.h |    1 -
 src/modules/pico.c         |   36 ++++++++++++-------------------
 11 files changed, 111 insertions(+), 110 deletions(-)

diff --git a/src/modules/cicero.c b/src/modules/cicero.c
index 1ad1b8f..0ea822b 100644
--- a/src/modules/cicero.c
+++ b/src/modules/cicero.c
@@ -31,6 +31,7 @@
 #include <fcntl.h>
 #include <langinfo.h>
 #include <sys/stat.h>
+#include <semaphore.h>
 
 #include "module_utils.h"
 
@@ -44,7 +45,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,8 +206,8 @@ int module_init(char **status_info)
  cicero_message = g_malloc(sizeof(char *));
  *cicero_message = NULL;
 
- cicero_semaphore = module_semaphore_init();
-
+ sem_init(&cicero_semaphore , 0, 0);
+ 
  DBG("Cicero: creating new thread for cicero_tracking\n");
  cicero_speaking = 0;
  ret =
@@ -257,7 +258,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 +296,8 @@ int module_close(void)
 
  if (module_terminate_thread(cicero_speaking_thread) != 0)
   return -1;
-
+  
+ sem_destroy(&cicero_semaphore );
  return 0;
 }
 
@@ -314,7 +316,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..5061ef1 100644
--- a/src/modules/dummy.c
+++ b/src/modules/dummy.c
@@ -30,6 +30,7 @@
 #endif
 
 #include <glib.h>
+#include <semaphore.h>
 
 #include <speechd_types.h>
 
@@ -45,7 +46,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,8 +69,8 @@ int module_init(char **status_info)
 
  *status_info = NULL;
 
- dummy_semaphore = module_semaphore_init();
-
+ sem_init(&dummy_semaphore, 0, 0);
+ 
  DBG("Dummy: creating new thread for dummy_speak\n");
  dummy_speaking = 0;
  ret = pthread_create(&dummy_speak_thread, NULL, _dummy_speak, NULL);
@@ -108,7 +109,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 +154,8 @@ int module_close(void)
 
  if (module_terminate_thread(dummy_speak_thread) != 0)
   return -1;
+  
+ sem_destroy(&dummy_semaphore );
 
  return 0;
 }
@@ -168,7 +171,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..0484363 100644
--- a/src/modules/espeak.c
+++ b/src/modules/espeak.c
@@ -34,6 +34,7 @@
 /* System includes. */
 #include <string.h>
 #include <glib.h>
+#include <semaphore.h>
 
 /* espeak header file */
 #include <espeak/speak_lib.h>
@@ -87,9 +88,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 +293,8 @@ 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();
+ sem_init(&espeak_stop_or_pause_semaphore, 0, 0);
+ 
  ret =
      pthread_create(&espeak_stop_or_pause_thread, NULL,
       _espeak_stop_or_pause, NULL);
@@ -303,7 +305,8 @@ int module_init(char **status_info)
   return FATAL_ERROR;
  }
 
- espeak_play_semaphore = module_semaphore_init();
+ sem_init(&espeak_play_semaphore, 0, 0);
+ 
  DBG("Espeak: Creating new thread for playback.");
  ret = pthread_create(&espeak_play_thread, NULL, _espeak_play, NULL);
  if (ret != OK) {
@@ -443,7 +446,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 +479,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 +505,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 +543,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 +807,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 +1044,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 +1089,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..14c23a9 100644
--- a/src/modules/festival.c
+++ b/src/modules/festival.c
@@ -26,6 +26,7 @@
 #endif
 
 #include <stdio.h>
+#include <semaphore.h>
 
 #include <speechd_types.h>
 #include "fdsetconv.h"
@@ -40,7 +41,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 +286,9 @@ 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)
-  return -1;
+
+ sem_init(&festival_semaphore, 0, 0);
+ 
  DBG("Festival: creating new thread for festival_speak\n");
  festival_speaking = 0;
  ret =
@@ -398,7 +399,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 +477,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 +613,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..d883287 100644
--- a/src/modules/flite.c
+++ b/src/modules/flite.c
@@ -26,6 +26,8 @@
 #include <config.h>
 #endif
 
+#include <semaphore.h>
+
 #include <flite/flite.h>
 #include "spd_audio.h"
 
@@ -43,7 +45,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,8 +127,8 @@ int module_init(char **status_info)
  flite_message = g_malloc(sizeof(char *));
  *flite_message = NULL;
 
- flite_semaphore = module_semaphore_init();
-
+ sem_init(&flite_semaphore, 0, 0);
+ 
  DBG("Flite: creating new thread for flite_speak\n");
  flite_speaking = 0;
  ret = pthread_create(&flite_speak_thread, NULL, _flite_speak, NULL);
@@ -177,7 +179,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 +231,7 @@ int module_close(void)
   return -1;
 
  g_free(flite_voice);
+ sem_destroy(&flite_semaphore);
 
  return 0;
 }
@@ -273,7 +276,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..8ef07df 100644
--- a/src/modules/generic.c
+++ b/src/modules/generic.c
@@ -27,6 +27,7 @@
 #endif
 
 #include <glib.h>
+#include <semaphore.h>
 
 #include <speechd_types.h>
 
@@ -42,7 +43,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,8 +150,9 @@ int module_init(char **status_info)
  generic_msg_language->name = g_strdup("english");
 
  generic_message = g_malloc(sizeof(char *));
- generic_semaphore = module_semaphore_init();
-
+ 
+ sem_init(&generic_semaphore, 0, 0);
+ 
  DBG("Generic: creating new thread for generic_speak\n");
  generic_speaking = 0;
  ret = pthread_create(&generic_speak_thread, NULL, _generic_speak, NULL);
@@ -227,7 +229,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 +275,8 @@ int module_close(void)
 
  if (module_terminate_thread(generic_speak_thread) != 0)
   return -1;
+  
+ sem_destroy(&generic_semaphore);
 
  return 0;
 }
@@ -320,7 +324,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..7273271 100644
--- a/src/modules/ibmtts.c
+++ b/src/modules/ibmtts.c
@@ -51,6 +51,7 @@
 /* System includes. */
 #include <string.h>
 #include <glib.h>
+#include <semaphore.h>
 
 /* IBM Eloquence Command Interface.
    Won't exist unless IBM TTS or IBM TTS SDK is installed. */
@@ -160,9 +161,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 +494,8 @@ 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();
+ sem_init(&ibmtts_stop_or_pause_semaphore, 0, 0);
+ 
  ret =
      pthread_create(&ibmtts_stop_or_pause_thread, NULL,
       _ibmtts_stop_or_pause, NULL);
@@ -509,7 +511,8 @@ int module_init(char **status_info)
  }
 
  DBG("Ibmtts: Creating new thread for playback.");
- ibmtts_play_semaphore = module_semaphore_init();
+ sem_init(&ibmtts_play_semaphore, 0, 0);
+ 
  ret = pthread_create(&ibmtts_play_thread, NULL, _ibmtts_play, NULL);
  if (0 != ret) {
   DBG("Ibmtts: play thread creation failed.");
@@ -522,7 +525,8 @@ int module_init(char **status_info)
  }
 
  DBG("Ibmtts: Creating new thread for IBM TTS synthesis.");
- ibmtts_synth_semaphore = module_semaphore_init();
+ sem_init(&ibmtts_synth_semaphore, 0, 0);
+ 
  ret = pthread_create(&ibmtts_synth_thread, NULL, _ibmtts_synth, NULL);
  if (0 != ret) {
   DBG("Ibmtts: synthesis thread creation failed.");
@@ -611,7 +615,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 +635,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 +657,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 +686,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 +705,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 +780,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 +924,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 +962,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 +1374,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 +1387,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 +1539,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..6ea2c87 100644
--- a/src/modules/ivona.c
+++ b/src/modules/ivona.c
@@ -29,6 +29,8 @@
 #include <config.h>
 #endif
 
+#include <semaphore.h>
+
 #include <libdumbtts.h>
 #include "spd_audio.h"
 
@@ -51,7 +53,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,8 +147,8 @@ module_init(char **status_info)
     ivona_message = g_malloc (sizeof (char*));
     *ivona_message = NULL;
 
-    ivona_semaphore = module_semaphore_init();
-
+    sem_init(&ivona_semaphore, 0, 0);
+ 
     DBG("Ivona: creating new thread for ivona_speak\n");
     ivona_speaking = 0;
     ret = pthread_create(&ivona_speak_thread, NULL, _ivona_speak, NULL);
@@ -204,7 +206,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 +257,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 +426,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..0aa90cf 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,15 +397,9 @@ 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);
-  return -1;
- }
-
+ sem_init(&pico_play_semaphore, 0, 0);
+ sem_init(&pico_idle_semaphore, 0, 0);
+ 
  if ((pico_play_thread = g_thread_create((GThreadFunc) pico_play_func,
       NULL, TRUE, &error)) == NULL) {
   *status_info = g_strdup_printf(MODULE_NAME
@@ -558,7 +552,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 +567,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 +591,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 +608,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 +617,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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]