[asterisk-commits] mmichelson: trunk r168898 - /trunk/res/res_timing_timerfd.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Jan 16 13:54:39 CST 2009


Author: mmichelson
Date: Fri Jan 16 13:54:39 2009
New Revision: 168898

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=168898
Log:
Fix a logic error that occur when using the timerfd interface

This sequence of events posed a problem

timerfd_timer_open
timerfd_timer_enable_continuous
timerfd_timer_set_rate
timerfd_timer_disable_continuous

The reason was that the timing module was written under the assumption
that timerfd_timer_set_rate would not be called between enabling and
disabling continuous mode. What happened in this situation was that 
timerfd_timer_enable_continuous saved off our previously set timer (in this
situation a 0 timer, meaning it never runs out). Then timerfd_timer_disable_continuous
would restore this 0 timer, even though it logically should set the timer to be whatever
was set in timerfd_timer_set_rate.

Now the behavior in timerfd_timer_set_rate is to overwrite the saved timer that may
or may not have been set in timerfd_timer_enable_continuous. Even if
timerfd_timer_enable_continuous has not been previously called, this will not harm the
operation.

Thanks to Terry Wilson for discovering the problem and giving me a really great debug
capture that pointed out the problem clearly


Modified:
    trunk/res/res_timing_timerfd.c

Modified: trunk/res/res_timing_timerfd.c
URL: http://svn.digium.com/svn-view/asterisk/trunk/res/res_timing_timerfd.c?view=diff&rev=168898&r1=168897&r2=168898
==============================================================================
--- trunk/res/res_timing_timerfd.c (original)
+++ trunk/res/res_timing_timerfd.c Fri Jan 16 13:54:39 2009
@@ -131,13 +131,21 @@
 
 static int timerfd_timer_set_rate(int handle, unsigned int rate)
 {
-	struct itimerspec itspec;
-	itspec.it_value.tv_sec = 0;
-	itspec.it_value.tv_nsec = rate ? (long) (1000000000 / rate) : 0L;
-	itspec.it_interval.tv_sec = itspec.it_value.tv_sec;
-	itspec.it_interval.tv_nsec = itspec.it_value.tv_nsec;
-
-	return timerfd_settime(handle, 0, &itspec, NULL);
+	struct timerfd_timer *our_timer, find_helper = {
+		.handle = handle,
+	};
+
+	if (!(our_timer = ao2_find(timerfd_timers, &find_helper, OBJ_POINTER))) {
+		ast_log(LOG_ERROR, "Couldn't find timer with handle %d\n", handle);
+		return -1;
+	}
+
+	our_timer->saved_timer.it_value.tv_sec = 0;
+	our_timer->saved_timer.it_value.tv_nsec = rate ? (long) (1000000000 / rate) : 0L;
+	our_timer->saved_timer.it_interval.tv_sec = our_timer->saved_timer.it_value.tv_sec;
+	our_timer->saved_timer.it_interval.tv_nsec = our_timer->saved_timer.it_value.tv_nsec;
+
+	return timerfd_settime(handle, 0, &our_timer->saved_timer, NULL);
 }
 
 static void timerfd_timer_ack(int handle, unsigned int quantity)




More information about the asterisk-commits mailing list