Question

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() member function.

Was it helpful?

Solution

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

OTHER TIPS

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.

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top