[Freeswitch-svn] [commit] r4410 - freeswitch/trunk/src/mod/timers/mod_softtimer

Freeswitch SVN anthm at freeswitch.org
Wed Feb 28 10:14:39 EST 2007


Author: anthm
Date: Wed Feb 28 10:14:39 2007
New Revision: 4410

Modified:
   freeswitch/trunk/src/mod/timers/mod_softtimer/mod_softtimer.c

Log:
fix possible endless loop race during shutdown

Modified: freeswitch/trunk/src/mod/timers/mod_softtimer/mod_softtimer.c
==============================================================================
--- freeswitch/trunk/src/mod/timers/mod_softtimer/mod_softtimer.c	(original)
+++ freeswitch/trunk/src/mod/timers/mod_softtimer/mod_softtimer.c	Wed Feb 28 10:14:39 2007
@@ -62,6 +62,10 @@
 {
 	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 @@
 {
 	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 @@
 	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 @@
 	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 {



More information about the Freeswitch-svn mailing list