Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
Ratas
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Ratas
Commits
0f379ac1
Commit
0f379ac1
authored
Jul 22, 2016
by
Juho Snellman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a usage example
parent
0023f343
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
0 deletions
+44
-0
src/timer-wheel.h
src/timer-wheel.h
+44
-0
No files found.
src/timer-wheel.h
View file @
0f379ac1
...
...
@@ -34,6 +34,50 @@
// events are promoted from the second wheel to the core. On each
// rotation of the second wheel, one slot's worth of events is
// promoted from the third wheel to the second, and so on.
//
// The basic usage is to create a single TimerWheel object and
// multiple TimerEvent or MemberTimerEvent objects. The events are
// scheduled for execution using TimerWheel::schedule() or
// TimerWheel::schedule_in_range(), or unscheduled using the event's
// cancel() method.
//
// Example usage:
//
// typedef std::function<void()> Callback;
// TimerWheel timers;
// int count = 0;
// TimerEvent<Callback> timer([&count] () { ++count; });
//
// timers.schedule(&timer, 5);
// timers.advance(4);
// assert(count == 0);
// timers.advance(1);
// assert(count == 1);
//
// timers.schedule(&timer, 5);
// timer.cancel();
// timers.advance(4);
// assert(count == 1);
//
// To tie events to specific member functions of an object instead of
// a callback function, use MemberTimerEvent instead of TimerEvent.
// For example:
//
// class Test {
// public:
// Test() : inc_timer_(this) {
// }
// void start(TimerWheel* timers) {
// timers->schedule(&inc_timer_, 10);
// }
// void on_inc() {
// count_++;
// }
// int count() { return count_; }
// private:
// MemberTimerEvent<Test, &Test::on_inc> inc_timer_;
// int count_ = 0;
// };
#ifndef _TIMER_WHEEL_H
#define _TIMER_WHEEL_H
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment