X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=otk%2Ftimer.cc;h=2e2205f78fa0d960f58675fadb7fe1ed2e59a2eb;hb=5a139f7263e33b499836f5df9ac37400e02c32f9;hp=b2b85a661fa9b8a19ed7b3770b8c13caf6ee6cfe;hpb=9259ec5732851dd66f7c598d629e3808ac7ab3d8;p=chaz%2Fopenbox diff --git a/otk/timer.cc b/otk/timer.cc index b2b85a66..2e2205f7 100644 --- a/otk/timer.cc +++ b/otk/timer.cc @@ -1,12 +1,11 @@ -// -*- mode: C++; indent-tabs-mode: nil; -*- +// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- #ifdef HAVE_CONFIG_H # include "../config.h" #endif // HAVE_CONFIG_H #include "timer.hh" -#include "display.hh" -#include "util.hh" +#include "timerqueuemanager.hh" namespace otk { @@ -36,17 +35,17 @@ static timeval normalizeTimeval(const timeval &tm) OBTimer::OBTimer(OBTimerQueueManager *m, OBTimeoutHandler h, OBTimeoutData d) { - manager = m; - handler = h; - data = d; + _manager = m; + _handler = h; + _data = d; - recur = timing = False; + _recur = _timing = false; } OBTimer::~OBTimer(void) { - if (timing) stop(); + if (_timing) stop(); } @@ -69,37 +68,33 @@ void OBTimer::start(void) { gettimeofday(&_start, 0); - if (! timing) { - timing = True; - manager->addTimer(this); + if (! _timing) { + _timing = true; + _manager->addTimer(this); } } void OBTimer::stop(void) { - timing = False; + if (_timing) { + _timing = false; - manager->removeTimer(this); -} - - -void OBTimer::halt(void) -{ - timing = False; + _manager->removeTimer(this); + } } -void OBTimer::fireTimeout(void) +void OBTimer::fire(void) { - if (handler) - handler(data); + if (_handler) + _handler(_data); } -timeval OBTimer::timeRemaining(const timeval &tm) const +timeval OBTimer::remainingTime(const timeval &tm) const { - timeval ret = endpoint(); + timeval ret = endTime(); ret.tv_sec -= tm.tv_sec; ret.tv_usec -= tm.tv_usec; @@ -108,7 +103,7 @@ timeval OBTimer::timeRemaining(const timeval &tm) const } -timeval OBTimer::endpoint(void) const +timeval OBTimer::endTime(void) const { timeval ret; @@ -121,66 +116,10 @@ timeval OBTimer::endpoint(void) const bool OBTimer::shouldFire(const timeval &tm) const { - timeval end = endpoint(); + timeval end = endTime(); return ! ((tm.tv_sec < end.tv_sec) || (tm.tv_sec == end.tv_sec && tm.tv_usec < end.tv_usec)); } - -void OBTimerQueueManager::fire() -{ - fd_set rfds; - timeval now, tm, *timeout = (timeval *) 0; - - const int xfd = ConnectionNumber(otk::OBDisplay::display); - - FD_ZERO(&rfds); - FD_SET(xfd, &rfds); // break on any x events - - if (! timerList.empty()) { - const OBTimer* const timer = timerList.top(); - - gettimeofday(&now, 0); - tm = timer->timeRemaining(now); - - timeout = &tm; - } - - select(xfd + 1, &rfds, 0, 0, timeout); - - // check for timer timeout - gettimeofday(&now, 0); - - // there is a small chance for deadlock here: - // *IF* the timer list keeps getting refreshed *AND* the time between - // timer->start() and timer->shouldFire() is within the timer's period - // then the timer will keep firing. This should be VERY near impossible. - while (! timerList.empty()) { - OBTimer *timer = timerList.top(); - if (! timer->shouldFire(now)) - break; - - timerList.pop(); - - timer->fireTimeout(); - timer->halt(); - if (timer->isRecurring()) - timer->start(); - } -} - - -void OBTimerQueueManager::addTimer(OBTimer *timer) -{ - assert(timer); - timerList.push(timer); -} - -void OBTimerQueueManager::removeTimer(OBTimer* timer) -{ - assert(timer); - timerList.release(timer); -} - }