]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
fix possible endless loop race during shutdown
authorAnthony Minessale <anthony.minessale@gmail.com>
Wed, 28 Feb 2007 15:14:39 +0000 (15:14 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Wed, 28 Feb 2007 15:14:39 +0000 (15:14 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4410 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/timers/mod_softtimer/mod_softtimer.c

index 810c5fa6440399e565a7ceb1c24ee079661303b6..b616fd0074297b134064099e70d441eacceb28f7 100644 (file)
@@ -62,6 +62,10 @@ static inline switch_status_t timer_init(switch_timer_t *timer)
 {
        timer_private_t *private_info;
 
+       if (globals.RUNNING != 1) {
+               return SWITCH_STATUS_FALSE;
+       }
+
        if ((private_info = switch_core_alloc(timer->memory_pool, sizeof(*private_info)))) {
                switch_mutex_lock(globals.mutex);
                TIMER_MATRIX[timer->interval].count++;
@@ -78,6 +82,10 @@ static inline switch_status_t timer_step(switch_timer_t *timer)
 {
        timer_private_t *private_info = timer->private_info;
 
+       if (globals.RUNNING != 1) {
+               return SWITCH_STATUS_FALSE;
+       }
+
     private_info->reference += timer->interval;
     return SWITCH_STATUS_SUCCESS;
 }
@@ -88,11 +96,17 @@ static inline switch_status_t timer_next(switch_timer_t *timer)
        timer_private_t *private_info = timer->private_info;
     
        timer_step(timer);
-       while (TIMER_MATRIX[timer->interval].tick < private_info->reference) {
+
+       while (globals.RUNNING == 1 && TIMER_MATRIX[timer->interval].tick < private_info->reference) {
         switch_yield(1000);
        }
-       timer->samplecount += timer->samples;
-       return SWITCH_STATUS_SUCCESS;
+
+       if (globals.RUNNING == 1) {
+               timer->samplecount += timer->samples;
+               return SWITCH_STATUS_SUCCESS;
+       }
+
+       return SWITCH_STATUS_FALSE;
 }
 
 static inline switch_status_t timer_check(switch_timer_t *timer)
@@ -102,6 +116,10 @@ static inline switch_status_t timer_check(switch_timer_t *timer)
        switch_status_t status = SWITCH_STATUS_SUCCESS;
     uint64_t diff;
 
+       if (globals.RUNNING != 1) {
+               return SWITCH_STATUS_SUCCESS;
+       }
+
        if (TIMER_MATRIX[timer->interval].tick < private_info->reference) {
         diff = private_info->reference - TIMER_MATRIX[timer->interval].tick;
        } else {