diff options
Diffstat (limited to 'src/utils/timer.cpp')
-rw-r--r-- | src/utils/timer.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/utils/timer.cpp b/src/utils/timer.cpp index 97965c7..0e9a6a7 100644 --- a/src/utils/timer.cpp +++ b/src/utils/timer.cpp @@ -19,6 +19,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include <time.h> #include "timer.h" namespace tmwserv @@ -33,6 +34,17 @@ Timer::Timer(unsigned int ms, bool createActive) lastpulse = getTimeInMillisec(); }; +void Timer::sleep() +{ + if (!active) return; + uint64_t now = getTimeInMillisec(); + if (now - lastpulse >= interval) return; + struct timespec req; + req.tv_sec = 0; + req.tv_nsec = (interval - (now - lastpulse)) * (1000 * 1000); + nanosleep(&req, 0); +} + int Timer::poll() { int elapsed = 0; |