/* * Copyright (c) 2002, Stefan Farfeleder * $Id: clock.cc,v 1.2 2002/09/05 22:20:32 stefan Exp $ */ #include #if defined(HAVE_CONFIG_H) #include "config.h" #endif #if defined(HAVE_SYS_TIME_H) #include #endif #if defined(_WIN32) #include #include #endif #include "exception.h" #include "clock.h" JFK::clock::clock() : timer(0) { } void JFK::clock::start() { #if defined(HAVE_GETTIMEOFDAY) timeval t; if (gettimeofday(&t, NULL) != 0) throw exception_e("gettimeofday"); timer = t.tv_sec * 1000000lu + t.tv_usec; #elif defined(_WIN32) timer = GetTickCount() * 1000lu; #else #error "don't know how to implement clock::start()" #endif } unsigned long JFK::clock::diff() { unsigned long oldtimer = timer; start(); return timer - oldtimer; } void JFK::clock::delay(unsigned long micsecs) { #if defined(HAVE_NANOSLEEP) timespec ts; ts.tv_sec = 0; ts.tv_nsec = micsecs * 1000; /* simply ignore EINTR */ nanosleep(&ts, NULL); #elif defined(_WIN32) Sleep(micsecs); #else #error "don't know how to implement clock::delay()" #endif }