[asterisk-commits] russell: branch group/timing r122804 - /team/group/timing/res/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Sun Jun 15 11:08:36 CDT 2008
Author: russell
Date: Sun Jun 15 11:08:35 2008
New Revision: 122804
URL: http://svn.digium.com/view/asterisk?view=rev&rev=122804
Log:
Re-do the timing thread. Instead of trying to get exactly one iteration of the
loop every 20 ms, get roughly one iteration every 10 ms. It seems to work well
enough for 1 tick / 20 ms timers.
Modified:
team/group/timing/res/res_timing_pthread.c
Modified: team/group/timing/res/res_timing_pthread.c
URL: http://svn.digium.com/view/asterisk/team/group/timing/res/res_timing_pthread.c?view=diff&rev=122804&r1=122803&r2=122804
==============================================================================
--- team/group/timing/res/res_timing_pthread.c (original)
+++ team/group/timing/res/res_timing_pthread.c Sun Jun 15 11:08:35 2008
@@ -83,7 +83,8 @@
unsigned int rate;
/*! Interval in ms for current rate */
unsigned int interval;
- struct timeval last_tick;
+ unsigned int tick_count;
+ struct timeval start;
};
static void pthread_timer_destructor(void *obj);
@@ -141,9 +142,11 @@
}
ao2_lock(timer);
+ timer->rate = rate;
timer->state = rate ? TIMER_STATE_TICKING : TIMER_STATE_IDLE;
- timer->rate = rate;
timer->interval = rate ? roundf(1000.0 / ((float) rate)) : 0;
+ timer->start = rate ? ast_tvnow() : ast_tv(0, 0);
+ timer->tick_count = 0;
ao2_unlock(timer);
ao2_ref(timer, -1);
@@ -293,11 +296,14 @@
if (timer->state == TIMER_STATE_IDLE || timer->state == TIMER_STATE_CONTINUOUS) {
return 0;
}
-
+
now = ast_tvnow();
- if (ast_tvdiff_ms(now, timer->last_tick) >= timer->interval) {
- timer->last_tick = now;
+ if (timer->tick_count < (ast_tvdiff_ms(now, timer->start) / timer->interval)) {
+ timer->tick_count++;
+ if (!timer->tick_count) {
+ timer->start = now;
+ }
return 1;
}
@@ -396,30 +402,13 @@
static void *do_timing(void *arg)
{
- struct timeval base = ast_tvnow();
- int skew = 0, previous_skew = 0, last_adjust = 0;
-
while (!timing_thread.stop) {
- struct timeval next_wakeup, now;
+ struct timeval next_wakeup;
struct timespec ts = { 0, };
ao2_callback(pthread_timers, 0, run_timer, NULL);
- if (previous_skew && skew) {
- int adjust = abs(skew - previous_skew), new_adjust = 0;
-
- if (adjust > 0) {
- new_adjust = abs(adjust - last_adjust);
- }
- last_adjust = new_adjust;
-
- base = ast_tvadd(base, ast_tv(0, (TIMING_INTERVAL - new_adjust) * 1000));
- } else {
- base = ast_tvadd(base, ast_tv(0, TIMING_INTERVAL * 1000));
- }
-
- now = ast_tvnow();
- next_wakeup = ast_tvadd(now, ast_tvsub(base, now));
+ next_wakeup = ast_tvadd(ast_tvnow(), ast_tv(0, 10000));
ts.tv_sec = next_wakeup.tv_sec;
ts.tv_nsec = next_wakeup.tv_usec * 1000;
@@ -429,9 +418,6 @@
ast_cond_timedwait(&timing_thread.cond, &timing_thread.lock, &ts);
}
ast_mutex_unlock(&timing_thread.lock);
-
- previous_skew = skew;
- skew = ast_tvdiff_ms(ast_tvnow(), next_wakeup);
}
return NULL;
More information about the asterisk-commits
mailing list