diff options
Diffstat (limited to 'src/server/timer.cc')
-rw-r--r-- | src/server/timer.cc | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/server/timer.cc b/src/server/timer.cc new file mode 100644 index 0000000..c8e6975 --- /dev/null +++ b/src/server/timer.cc @@ -0,0 +1,37 @@ +/* server/timer.cc + This file is part of the Osirion project and is distributed under + the terms and conditions of the GNU General Public License version 2 +*/ + +#include "timer.h" +#include <unistd.h> + +Timer::Timer() +{ + gettimeofday(&this->timer_tick, &this->timer_tz); + this->timer_elapsed = 0; +} + +Timer::~Timer() +{ +} + +void Timer::mark() +{ + gettimeofday(&timer_tick, &timer_tz); +} + +float Timer::elapsed() +{ timeval tick; + + gettimeofday(&tick, &timer_tz); + + // calculate elapsed time in 10^-6 seconds + long delta = (tick.tv_sec - timer_tick.tv_sec) * 1000000 + (tick.tv_usec - timer_tick.tv_usec); + return( (float) delta / 1000000); +} + +void Timer::sleep(float seconds) +{ + usleep((useconds_t) seconds*1000000.0f); +} |