speechd-discuss
[Top][All Lists]
Advanced

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

[PATCH 2/2] wait until stop and pause events were sent in pico


From: Andrei Kholodnyi
Subject: [PATCH 2/2] wait until stop and pause events were sent in pico
Date: Wed, 10 Nov 2010 21:05:54 +0100

pico didn't wait in module_stop and module_pause functions
until events were send to server. it causes that pico was still
not in STATE_IDLE, and new messages were dropped
---
 src/modules/pico.c |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/modules/pico.c b/src/modules/pico.c
index bc3cd59..ac75c4e 100644
--- a/src/modules/pico.c
+++ b/src/modules/pico.c
@@ -102,6 +102,7 @@ static const SPDVoice *pico_voices_list[] = {
 
 static GThread *pico_play_thread;
 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;
@@ -259,11 +260,14 @@ 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);
+
                }
 
                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);
                }
 
                DBG(MODULE_NAME ": state %d", pico_state);
@@ -382,9 +386,10 @@ int module_init(char **status_info)
                g_thread_init(NULL);
 
        pico_play_semaphore = module_semaphore_init();
-       if (pico_play_semaphore == NULL) {
+       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 play thread semaphore!");
+                       "Failed to initialize semaphores!");
                DBG(MODULE_NAME": %s", *status_info);
                return -1;
        }
@@ -557,6 +562,7 @@ int module_stop(void)
        }
 
        g_atomic_int_set(&pico_state, STATE_STOP);
+       sem_wait(pico_idle_semaphore);
 
        /* reset Pico engine. */
        if((ret = pico_resetEngine(picoEngine, PICO_RESET_SOFT))) {
@@ -581,6 +587,7 @@ size_t module_pause(void)
        }
 
        g_atomic_int_set(&pico_state, STATE_PAUSE);
+       sem_wait(pico_idle_semaphore);
 
        /* reset Pico engine. */
        if((ret = pico_resetEngine(picoEngine, PICO_RESET_SOFT))) {
@@ -609,5 +616,6 @@ void module_close(int status)
                picoSystem = NULL;
        }
 
+       g_free(pico_idle_semaphore);
        g_free(pico_play_semaphore);
 }
-- 
1.6.0.4




reply via email to

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