timing wheel implementation
C
Switch branches/tags
Nothing to show
Latest commit 0dc372e Jul 25, 2012 @hoterran add compile in README.md
Permalink
Failed to load latest commit information.
README.md add compile in README.md Jul 25, 2012
adlist.c init Jul 9, 2012
adlist.h init Jul 9, 2012
timer.c fix add task, rotation_count bug Jul 25, 2012

README.md

#simple-timing-wheel

a simple timing-wheel timer, use double list.

##data str

  • wheels is a array, wheels_size is its' size.
  • wheel is a double list array.
  • index is current wheel.
  • each tick, index increment, execute the task in current wheel, granularity is each tick consume time, unit is milliseconds,
  • first is the task 's first execute relative time, interval is the task 's execute interval, they are all milliseconds.
  • rotation_count, if task's first or interval is larger than max duration wheels, rotation_count will increment.
  • so before execute task, need check if global rotation_count is equal task rotation_count

##task type

  • Repeat: this task will repeat execute, after current executing, calc next index and add it into list.
  • Once: this task just execute once.

##compile

gcc -g -o d timer.c adlist.c

##use

  • create a wheels, wheel_size is 60 slot, granularity is 200ms.

Tw *tw = init(60, 200);

  • add three time event into wheels.

add(tw, 1000, 2000, a1, (void*)1, Repeat);

add(tw, 100000, 200000, a1, (void*)2, Once);

add(tw, 0, 10000, p1, tw, Repeat);

  • start timer

start(tw);