X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=otk%2Ftimer.cc;h=0a0083146afee234012a7e30796f33d4bd60b393;hb=a91a6f97daeb058f346246081e1c83a788787f9b;hp=2d36c7a05e8c476839711e5b9e3537212712568c;hpb=96a9196cbb71b7f8d5e3d98a92b2e59bb1b591a8;p=chaz%2Fopenbox diff --git a/otk/timer.cc b/otk/timer.cc index 2d36c7a0..0a008314 100644 --- a/otk/timer.cc +++ b/otk/timer.cc @@ -1,12 +1,20 @@ // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- -#ifdef HAVE_CONFIG_H -# include "../config.h" -#endif // HAVE_CONFIG_H +#include "config.h" #include "timer.hh" #include "display.hh" +extern "C" { +#ifdef HAVE_SYS_SELECT_H +# include +#endif // HAVE_SYS_SELECT_H + +#ifdef HAVE_SYS_TIME_H +# include +#endif +} + namespace otk { timeval Timer::_nearest_timeout, Timer::_now; @@ -52,8 +60,9 @@ void Timer::dispatchTimers(bool wait) while (!_q.empty()) { curr = _q.top(); - /* since we overload the destructor to keep from removing from the middle of - the priority queue, set _del_me, we have to do our real delete in here. + /* since we overload the destructor to keep from removing from the middle + of the priority queue, set _del_me, we have to do our real delete in + here. */ if (curr->_del_me) { _q.pop(); @@ -66,15 +75,20 @@ void Timer::dispatchTimers(bool wait) 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. + /* 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; } if (wait) { @@ -82,9 +96,9 @@ void Timer::dispatchTimers(bool wait) fd = ConnectionNumber(**display); FD_ZERO(&selset); FD_SET(fd, &selset); - if (nearestTimeout(next)) + if (nearestTimeout(next)) { select(fd + 1, &selset, NULL, NULL, &next); - else + } else select(fd + 1, &selset, NULL, NULL, NULL); } }