tags:

views:

1198

answers:

3

What I'm looking for is a simple timer queue possibly with an external timing source and a poll method (in this way it will be multi-platform). Each enqueued message could be an object implementing a simple interface with a virtual onTimer() method.

+1  A: 

There is a nice article in CodeProject, here, that describes the various timers available in Windows, and has chapters titled "Queue timers" and "Make your own timer".

For platform independence, you'd have to make implementations for the different platforms inside #ifdef -- #endif pairs. I can see nothing less ugly than that.

TonJ
+2  A: 

Boost::ASIO contains an async timer implementation. That might work for you.

Len Holgate
Thanks, this looks quite extensible though it kind of misses on the 'lightweight' part--the compiled code is very small but the additional sources needed are heavy.
Milen A. Radev
You can also get a 'non boost' version of ASIO from http://think-async.blogspot.com/2008/05/boostasio-vs-asio.html; which is a little easier to deal with..
Len Holgate
A: 

It doesn't fit all of your criteria, but... I wrote a series of blog posts about a timer queue for windows that is implemented in terms of an external time provider and that is either polled or driven by a thread. The series comes with source code and tests and the point of it was to demonstrate the testing of reasonably complex code. Anyway, you might be able to make use of some of the code or ideas if nobody comes up with a better fit.

Articles start here: http://www.lenholgate.com/archives/000306.html

Len Holgate