]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-7567 #resolve #comment additional occurrences beyond the initial patch discovered
authorAnthony Minessale <anthm@freeswitch.org>
Thu, 21 May 2015 14:50:49 +0000 (09:50 -0500)
committerAnthony Minessale <anthm@freeswitch.org>
Thu, 21 May 2015 14:50:49 +0000 (09:50 -0500)
src/include/switch_ivr.h
src/switch_core_memory.c
src/switch_ivr.c
src/switch_ivr_async.c
src/switch_log.c
src/switch_nat.c
src/switch_scheduler.c

index 20e1cdfa455c2412afcaa001b7c4df57234b7d76..155ba583fbdf80029207e6e7b7737eb1533ea8e4 100644 (file)
@@ -60,6 +60,7 @@ SWITCH_BEGIN_EXTERN_C struct switch_unicast_conninfo {
        int type;
        int transport;
        int stream_id;
+       switch_thread_t *thread;
 };
 typedef struct switch_unicast_conninfo switch_unicast_conninfo_t;
 
index 74e0fa70e01904cf7dffc935c187fe3f06b414fc..7b1ae8f1c2223251deced29596106a904ef1d3dc 100644 (file)
@@ -662,7 +662,6 @@ switch_memory_pool_t *switch_core_memory_init(void)
        switch_queue_create(&memory_manager.pool_recycle_queue, 50000, memory_manager.memory_pool);
 
        switch_threadattr_create(&thd_attr, memory_manager.memory_pool);
-       switch_threadattr_detach_set(thd_attr, 0);
 
        switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
        switch_thread_create(&pool_thread_p, thd_attr, pool_thread, NULL, memory_manager.memory_pool);
index ad9b6b11395dd42de903fd37395a1d77f7b59156..17289cec2e3e1a95e5b1ef2a8ba281eae954f676 100644 (file)
@@ -348,14 +348,12 @@ static void *SWITCH_THREAD_FUNC unicast_thread_run(switch_thread_t *thread, void
 
 static void unicast_thread_launch(switch_unicast_conninfo_t *conninfo)
 {
-       switch_thread_t *thread;
        switch_threadattr_t *thd_attr = NULL;
 
        switch_threadattr_create(&thd_attr, switch_core_session_get_pool(conninfo->session));
-       switch_threadattr_detach_set(thd_attr, 1);
        switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
        switch_set_flag_locked(conninfo, SUF_THREAD_RUNNING);
-       switch_thread_create(&thread, thd_attr, unicast_thread_run, conninfo, switch_core_session_get_pool(conninfo->session));
+       switch_thread_create(&conninfo->thread, thd_attr, unicast_thread_run, conninfo, switch_core_session_get_pool(conninfo->session));
 }
 
 SWITCH_DECLARE(switch_status_t) switch_ivr_deactivate_unicast(switch_core_session_t *session)
@@ -369,9 +367,13 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_deactivate_unicast(switch_core_sessio
        }
 
        if ((conninfo = switch_channel_get_private(channel, "unicast"))) {
+               switch_status_t st;
+
                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Shutting down unicast connection\n");
                switch_clear_flag_locked(conninfo, SUF_READY);
                switch_socket_shutdown(conninfo->socket, SWITCH_SHUTDOWN_READWRITE);
+               switch_thread_join(&st, conninfo->thread);
+               
                while (switch_test_flag(conninfo, SUF_THREAD_RUNNING)) {
                        switch_yield(10000);
                        if (++sanity >= 10000) {
index 67cd095474a095d712b4ea34128ddc5360acf77f..bc4d724a504d2fdd0bc0d028ac03c7e574d39d61 100644 (file)
@@ -4012,6 +4012,7 @@ struct speech_thread_handle {
        switch_mutex_t *mutex;
        switch_thread_cond_t *cond;
        switch_memory_pool_t *pool;
+       switch_thread_t *thread;
        int ready;
 };
 
@@ -4175,23 +4176,29 @@ static switch_bool_t speech_callback(switch_media_bug_t *bug, void *user_data, s
        frame.buflen = SWITCH_RECOMMENDED_BUFFER_SIZE;
 
        switch (type) {
-       case SWITCH_ABC_TYPE_INIT:{
-                       switch_thread_t *thread;
+       case SWITCH_ABC_TYPE_INIT:
+               {
                        switch_threadattr_t *thd_attr = NULL;
-
+                       
                        switch_threadattr_create(&thd_attr, sth->pool);
-                       switch_threadattr_detach_set(thd_attr, 1);
                        switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
-                       switch_thread_create(&thread, thd_attr, speech_thread, sth, sth->pool);
+                       switch_thread_create(&sth->thread, thd_attr, speech_thread, sth, sth->pool);
                }
                break;
-       case SWITCH_ABC_TYPE_CLOSE:{
+       case SWITCH_ABC_TYPE_CLOSE:
+               {
+                       switch_status_t st;
+
                        switch_core_asr_close(sth->ah, &flags);
                        if (sth->mutex && sth->cond && sth->ready) {
-                               switch_mutex_lock(sth->mutex);
-                               switch_thread_cond_signal(sth->cond);
-                               switch_mutex_unlock(sth->mutex);
+                               if (switch_mutex_trylock(sth->mutex) == SWITCH_STATUS_SUCCESS) {
+                                       switch_thread_cond_signal(sth->cond);
+                                       switch_mutex_unlock(sth->mutex);
+                               }
                        }
+                       
+                       switch_thread_join(&st, sth->thread);
+
                }
                break;
        case SWITCH_ABC_TYPE_READ:
index 00ae7c0ef181014f4da42bf38db26a26d17e51e5..c512b2d0c5787b778dddc2cb2180ea92a30e846e 100644 (file)
@@ -512,8 +512,6 @@ SWITCH_DECLARE(switch_status_t) switch_log_init(switch_memory_pool_t *pool, swit
        LOG_POOL = pool;
 
        switch_threadattr_create(&thd_attr, LOG_POOL);
-       switch_threadattr_detach_set(thd_attr, 1);
-
 
        switch_queue_create(&LOG_QUEUE, SWITCH_CORE_QUEUE_LEN, LOG_POOL);
 #ifdef SWITCH_LOG_RECYCLE
index d1ab09eba1d81f94d1a4e81f1f0234edbd0839a3..e18ad261f75f01e42596adf482f007e2aa41eb54 100644 (file)
@@ -365,7 +365,6 @@ SWITCH_DECLARE(void) switch_nat_thread_start(void)
        }
 
        switch_threadattr_create(&thd_attr, nat_globals_perm.pool);
-       switch_threadattr_detach_set(thd_attr, 1);
        switch_thread_create(&nat_thread_p, thd_attr, switch_nat_multicast_runtime, NULL, nat_globals_perm.pool);
 }
 
index e734bad087df5b4fed8e45020ab8895bbc1a8299..16fc59df406a347f010eafa5f57eabe8d6f34eff 100644 (file)
@@ -335,7 +335,6 @@ SWITCH_DECLARE(void) switch_scheduler_task_thread_start(void)
        switch_mutex_init(&globals.task_mutex, SWITCH_MUTEX_NESTED, globals.memory_pool);
        switch_queue_create(&globals.event_queue, 250000, globals.memory_pool);
 
-       switch_threadattr_detach_set(thd_attr, 1);
        switch_thread_create(&task_thread_p, thd_attr, switch_scheduler_task_thread, NULL, globals.memory_pool);
 }