/**
* @brief Stop a tw timer
* @param tw_timer_wheel_t * tw timer wheel object pointer
- * @param u32 pool_index user pool index, passed for consistency checking only
- * @param u32 timer_id 4 bit timer ID, passed for consistency checking only
* @param u32 handle timer cancellation returned by tw_timer_start
*/
-
void TW (tw_timer_stop) (TWT (tw_timer_wheel) * tw, u32 handle)
{
TWT (tw_timer) * t;
void
TW (tw_timer_wheel_init) (TWT (tw_timer_wheel) * tw,
void *expired_timer_callback,
- f64 timer_interval_in_seconds)
+ f64 timer_interval_in_seconds, u32 max_expirations)
{
int ring, slot;
tw_timer_wheel_slot_t *ts;
TWT (tw_timer) * t;
memset (tw, 0, sizeof (*tw));
tw->expired_timer_callback = expired_timer_callback;
+ tw->max_expirations = max_expirations;
if (timer_interval_in_seconds == 0.0)
{
clib_warning ("timer interval is zero");
* @param tw_timer_wheel_t * tw timer wheel template instance pointer
* @param f64 now the current time, e.g. from vlib_time_now(vm)
*/
-void TW (tw_timer_expire_timers) (TWT (tw_timer_wheel) * tw, f64 now)
+u32 TW (tw_timer_expire_timers) (TWT (tw_timer_wheel) * tw, f64 now)
{
u32 nticks, i;
tw_timer_wheel_slot_t *ts;
TWT (tw_timer) * t, *head;
u32 fast_wheel_index;
u32 next_index;
+ u32 nexpirations, total_nexpirations;
#if TW_TIMER_WHEELS > 1
u32 slow_wheel_index;
#endif
/* Shouldn't happen */
if (PREDICT_FALSE (now < tw->next_run_time))
- return;
+ return 0;
/* Number of ticks which have occurred */
nticks = tw->ticks_per_second * (now - tw->last_run_time);
if (nticks == 0)
- return;
+ return 0;
/* Remember when we ran, compute next runtime */
tw->next_run_time = (now + tw->timer_interval);
- tw->last_run_time = now;
+ total_nexpirations = 0;
for (i = 0; i < nticks; i++)
{
fast_wheel_index = tw->current_index[TW_TIMER_RING_FAST];
}
/* If any timers expired, tell the user */
- if (vec_len (tw->expired_timer_handles))
- tw->expired_timer_callback (tw->expired_timer_handles);
+ nexpirations = vec_len (tw->expired_timer_handles);
+ if (nexpirations)
+ {
+ tw->expired_timer_callback (tw->expired_timer_handles);
+ total_nexpirations += nexpirations;
+ }
tw->current_index[TW_TIMER_RING_FAST]++;
tw->current_tick++;
+
+ if (total_nexpirations >= tw->max_expirations)
+ break;
}
+
+ tw->last_run_time += i * tw->timer_interval;
+ return total_nexpirations;
}
/*