]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
freetdm: stop scheduler but do not destroy it until the very end (dup)
authorMoises Silva <moy@sangoma.com>
Tue, 28 Sep 2010 15:05:54 +0000 (11:05 -0400)
committerMoises Silva <moy@sangoma.com>
Tue, 28 Sep 2010 15:05:54 +0000 (11:05 -0400)
libs/freetdm/src/ftdm_io.c
libs/freetdm/src/ftdm_sched.c
libs/freetdm/src/include/private/ftdm_sched.h

index 299106f599a76367a397e4704bc9790c912c3e35..79d55c4d166bb54680f70e8f82b12a07a3abf68b 100644 (file)
@@ -4932,16 +4932,19 @@ FT_DECLARE(uint32_t) ftdm_running(void)
 FT_DECLARE(ftdm_status_t) ftdm_global_destroy(void)
 {
        ftdm_span_t *sp;
-       uint32_t sanity = 100;
 
        time_end();
 
+       /* many freetdm event loops rely on this variable to decide when to stop, do this first */
        globals.running = 0;    
 
-       ftdm_sched_destroy(&globals.timingsched);
+       /* stop the scheduling thread */
+       ftdm_free_sched_stop();
 
+       /* stop the cpu monitor thread */
        ftdm_cpu_monitor_stop();
 
+       /* now destroy channels and spans */
        globals.span_index = 0;
 
        ftdm_span_close_all();
@@ -4966,18 +4969,12 @@ FT_DECLARE(ftdm_status_t) ftdm_global_destroy(void)
        globals.spans = NULL;
        ftdm_mutex_unlock(globals.span_mutex);
 
+       /* destroy signaling and io modules */
        ftdm_unload_modules();
 
-       while (ftdm_free_sched_running() && --sanity) {
-               ftdm_log(FTDM_LOG_DEBUG, "Waiting for schedule thread to finish\n");
-               ftdm_sleep(100);
-       }
-
-       if (!sanity) {
-               ftdm_log(FTDM_LOG_CRIT, "schedule thread did not stop running, we may crash on shutdown\n");
-       }
-
+       /* finally destroy the globals */
        ftdm_mutex_lock(globals.mutex);
+       ftdm_sched_destroy(&globals.timingsched);
        hashtable_destroy(globals.interface_hash);
        hashtable_destroy(globals.module_hash); 
        hashtable_destroy(globals.span_hash);
index be21696d7193992cecc202b2c98a97d8cd7d4961..47df7d973cd455143d7669f9cb713cde85bc96f5 100644 (file)
@@ -176,6 +176,24 @@ FT_DECLARE(ftdm_bool_t) ftdm_free_sched_running(void)
        return sched_globals.running;
 }
 
+FT_DECLARE(ftdm_bool_t) ftdm_free_sched_stop(void)
+{
+       /* currently we really dont stop the thread here, we rely on freetdm being shutdown and ftdm_running() to be false 
+        * so the scheduling thread dies and we just wait for it here */
+       uint32_t sanity = 100;
+       while (ftdm_free_sched_running() && --sanity) {
+               ftdm_log(FTDM_LOG_DEBUG, "Waiting for main schedule thread to finish\n");
+               ftdm_sleep(100);
+       }
+
+       if (!sanity) {
+               ftdm_log(FTDM_LOG_CRIT, "schedule thread did not stop running, we may crash on shutdown\n");
+               return FTDM_FALSE;
+       }
+
+       return FTDM_TRUE;
+}
+
 FT_DECLARE(ftdm_status_t) ftdm_sched_create(ftdm_sched_t **sched, const char *name)
 {
        ftdm_sched_t *newsched = NULL;
index 9a222896f5ea1e00615f8485c61fac8eeec81191..c1818d8bb5ae3699176f66128374490bd92d9095 100644 (file)
@@ -95,6 +95,9 @@ FT_DECLARE(ftdm_status_t) ftdm_sched_global_init(void);
 /*! \brief Checks if the main scheduling thread is running */
 FT_DECLARE(ftdm_bool_t) ftdm_free_sched_running(void);
 
+/*! \brief Stop the main scheduling thread (if running) */
+FT_DECLARE(ftdm_bool_t) ftdm_free_sched_stop(void);
+
 #ifdef __cplusplus
 } 
 #endif