1#ifndef CLICK_TIMERWHEEL_HH
2#define CLICK_TIMERWHEEL_HH 1
4#include <click/algorithm.hh>
11 TimerWheel() : _index(0) {
14 void initialize(
int max) {
15 max = next_pow2(max + 2);
17 _buckets.resize(max, 0);
24 inline void schedule_after(T* obj, uint32_t timeout,
const std::function<
void(T*,T*)> setter) {
26 assert(timeout < _mask);
27 unsigned id = ((*(
volatile uint32_t*)&_index) + timeout) & _mask;
30 T* f = _buckets.unchecked_at(
id);
33 _buckets.unchecked_at(
id) = obj;
36 inline void schedule_after_mp(T* obj, uint32_t timeout,
const std::function<
void(T*,T*)> setter) {
37 _writers_lock.acquire();
38 unsigned id = ((*(
volatile uint32_t*)&_index) + timeout) & _mask;
41 T* f = _buckets.unchecked_at(
id);
43 _buckets.unchecked_at(
id) = obj;
45 _writers_lock.release();
51 inline void run_timers(std::function<T*(T*)> expire) {
52 T* f = _buckets.unchecked_at((_index) & _mask);
57 _buckets.unchecked_at((_index) & _mask) = 0;
61 bool debug_find(T*obj, std::function<T*(T*)> next ) {
63 for (
int i =0; i <= _mask; i++) {
64 T* a = _buckets[(
id + i) & _mask];
A recursive spinlock for SMP Click threads.
Definition sync.hh:439
Vector template.
Definition vector.hh:111