]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
make event thread start once there is an event
authorAnthony Minessale <anthony.minessale@gmail.com>
Fri, 14 Mar 2008 13:05:28 +0000 (13:05 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Fri, 14 Mar 2008 13:05:28 +0000 (13:05 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@7890 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/endpoints/mod_sofia/mod_sofia.c
src/mod/endpoints/mod_sofia/sofia_presence.c

index dceef86437814995310e6f2fe9e397abe327d1b4..c3480266350a25b0e24a82125a98cd7a1ed312bd 100644 (file)
@@ -1888,7 +1888,6 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_sofia_load)
 
        switch_queue_create(&mod_sofia_globals.presence_queue, 500000, mod_sofia_globals.pool);
        switch_queue_create(&mod_sofia_globals.mwi_queue, 500000, mod_sofia_globals.pool);
-       sofia_presence_event_thread_start();
 
        if (config_sofia(0, NULL) != SWITCH_STATUS_SUCCESS) {
                mod_sofia_globals.running = 0;
index 408834ec8005a816b530975635eb258197c48b0b..626d213bb195a4f6bc4ee1e25f3bbb30695fef3c 100644 (file)
@@ -485,16 +485,29 @@ done:
        switch_safe_free(user);
 }
 
+static int EVENT_THREAD_RUNNING = 0;
+static int EVENT_THREAD_STARTED = 0;
 
 void *SWITCH_THREAD_FUNC sofia_presence_event_thread_run(switch_thread_t *thread, void *obj)
 {
        void *pop;
-       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Event Thread Started\n");
+       int done = 0;
 
        switch_mutex_lock(mod_sofia_globals.mutex);
-       mod_sofia_globals.threads++;
+       if (!EVENT_THREAD_RUNNING) {
+               EVENT_THREAD_RUNNING++;
+               mod_sofia_globals.threads++;
+       } else {
+               done = 1;
+       }
        switch_mutex_unlock(mod_sofia_globals.mutex);
 
+       if (done) {
+               return NULL;
+       }
+
+       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Event Thread Started\n");
+       
        while (mod_sofia_globals.running == 1) {
                int count = 0;
                
@@ -541,8 +554,9 @@ void *SWITCH_THREAD_FUNC sofia_presence_event_thread_run(switch_thread_t *thread
 
        switch_mutex_lock(mod_sofia_globals.mutex);
        mod_sofia_globals.threads--;
+       EVENT_THREAD_RUNNING = EVENT_THREAD_STARTED = 0;
        switch_mutex_unlock(mod_sofia_globals.mutex);
-
+       
        return NULL;
 }
 
@@ -550,6 +564,19 @@ void sofia_presence_event_thread_start(void)
 {
        switch_thread_t *thread;
        switch_threadattr_t *thd_attr = NULL;
+       int done = 0;
+
+       switch_mutex_lock(mod_sofia_globals.mutex);
+       if (!EVENT_THREAD_STARTED) {
+               EVENT_THREAD_STARTED++;
+       } else {
+               done = 1;
+       }
+       switch_mutex_unlock(mod_sofia_globals.mutex);
+
+       if (done) {
+               return;
+       }
 
        switch_threadattr_create(&thd_attr, mod_sofia_globals.pool);
        switch_threadattr_detach_set(thd_attr, 1);
@@ -566,6 +593,10 @@ void sofia_presence_event_handler(switch_event_t *event)
        switch_event_dup(&cloned_event, event);
        switch_assert(cloned_event);
        switch_queue_push(mod_sofia_globals.presence_queue, cloned_event);
+
+       if (!EVENT_THREAD_STARTED) {
+               sofia_presence_event_thread_start();
+       }
 }
 
 void sofia_presence_mwi_event_handler(switch_event_t *event)
@@ -575,6 +606,10 @@ void sofia_presence_mwi_event_handler(switch_event_t *event)
        switch_event_dup(&cloned_event, event);
        switch_assert(cloned_event);
        switch_queue_push(mod_sofia_globals.mwi_queue, cloned_event);
+
+       if (!EVENT_THREAD_STARTED) {
+               sofia_presence_event_thread_start();
+       }
 }