diff options
author | mmichelson <mmichelson@f38db490-d61c-443f-a65b-d21fe96a405b> | 2009-01-16 19:54:39 +0000 |
---|---|---|
committer | mmichelson <mmichelson@f38db490-d61c-443f-a65b-d21fe96a405b> | 2009-01-16 19:54:39 +0000 |
commit | ab71278068baa80cdf738896fe2b2eee81f2d7f8 (patch) | |
tree | fec185bbfd4539cb506f8447adb48a01ad4abff5 /res | |
parent | 844a51b7f34c97e7fb73d6491d97a51a197c8bd9 (diff) |
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
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@168898 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'res')
-rw-r--r-- | res/res_timing_timerfd.c | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/res/res_timing_timerfd.c b/res/res_timing_timerfd.c index d0ad17520..60dc2d5ef 100644 --- a/res/res_timing_timerfd.c +++ b/res/res_timing_timerfd.c @@ -131,13 +131,21 @@ static void timerfd_timer_close(int handle) 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; + 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, &itspec, NULL); + return timerfd_settime(handle, 0, &our_timer->saved_timer, NULL); } static void timerfd_timer_ack(int handle, unsigned int quantity) |