-void OBTimer::start(void)
-{
- gettimeofday(&_start, 0);
+ // the queue is sorted, so if this timer shouldn't fire, none are ready
+ _nearest_timeout = curr->_timeout;
+ if (!timercmp(&_now, &_nearest_timeout, >))
+ break;
+
+ /* we set the last fired time to delay msec after the previous firing, then
+ re-insert. timers maintain their order and may trigger more than once
+ if they've waited more than one delay's worth of time.
+ */
+ _q.pop();
+ timevalAdd(curr->_last, curr->_delay);
+ curr->_action(curr->_data);
+ timevalAdd(curr->_timeout, curr->_delay);
+ _q.push(curr);
+
+ /* if at least one timer fires, then don't wait on X events, as there may
+ already be some in the queue from the timer callbacks.
+ */
+ wait = false;
+ }