]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add some more thread joins to avoid races
authorAnthony Minessale <anthony.minessale@gmail.com>
Mon, 2 Mar 2009 15:45:00 +0000 (15:45 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Mon, 2 Mar 2009 15:45:00 +0000 (15:45 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@12348 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/switch_core_memory.c
src/switch_time.c

index 0aec436e5d083d340ad0a191ecf1524089559511..35d292c53f2edb7f41555ab81fc617b16b415513 100644 (file)
@@ -440,11 +440,17 @@ static void *SWITCH_THREAD_FUNC pool_thread(switch_thread_t *thread, void *obj)
        return NULL;
 }
 
+static switch_thread_t *pool_thread_p = NULL;
+
 void switch_core_memory_stop(void)
 {
+       switch_status_t st;
+
        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Stopping memory pool queue.\n");
 #ifndef INSTANTLY_DESTROY_POOLS
        memory_manager.pool_thread_running = -1;
+       switch_thread_join(&st, pool_thread_p);
+       
        while (memory_manager.pool_thread_running) {
                switch_cond_next();
        }
@@ -454,7 +460,6 @@ void switch_core_memory_stop(void)
 switch_memory_pool_t *switch_core_memory_init(void)
 {
 #ifndef INSTANTLY_DESTROY_POOLS
-       switch_thread_t *thread;
        switch_threadattr_t *thd_attr;
 #endif
 #ifdef PER_POOL_LOCK
@@ -502,7 +507,7 @@ switch_memory_pool_t *switch_core_memory_init(void)
        switch_threadattr_detach_set(thd_attr, 1);
 
        switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
-       switch_thread_create(&thread, thd_attr, pool_thread, NULL, memory_manager.memory_pool);
+       switch_thread_create(&pool_thread_p, thd_attr, pool_thread, NULL, memory_manager.memory_pool);
 
        while (!memory_manager.pool_thread_running) {
                switch_cond_next();
index 4852428f8fab901be8ed56075bb458001083c771..7cfa3034828863c24c5c572c8b9942f5057d99b0 100644 (file)
@@ -113,7 +113,7 @@ static void do_sleep(switch_interval_time_t t)
 
 SWITCH_DECLARE(switch_time_t) switch_micro_time_now(void)
 {
-       return runtime.timestamp ? runtime.timestamp : switch_time_now();
+       return (globals.RUNNING == 1 && runtime.timestamp) ? runtime.timestamp : switch_time_now();
 }
 
 
@@ -195,7 +195,7 @@ SWITCH_DECLARE(void) switch_cond_next(void)
 #ifdef DISABLE_1MS_COND
        do_sleep(1000);
 #else
-       if (!runtime.timestamp || globals.use_cond_yield != 1) {
+       if (globals.RUNNING != 1 || !runtime.timestamp || globals.use_cond_yield != 1) {
                do_sleep(1000);
                return;
        }
@@ -210,7 +210,7 @@ SWITCH_DECLARE(void) switch_cond_yield(switch_interval_time_t t)
        switch_time_t want;
        if (!t) return;
 
-       if (!runtime.timestamp || globals.use_cond_yield != 1) {
+       if (globals.RUNNING != 1 || !runtime.timestamp || globals.use_cond_yield != 1) {
                do_sleep(t);
                return;
        }