class Clock { public: Clock() : offset_( 0 ) {} double time(); void adjustTime( double dt ); private: double offset_;};double Clock::time() { struct timeval tv; gettimeofday( &tv, 0 ); return (double)tv.tv_sec + 1e-6*(double)tv.tv_usec - offset_;}void Clock::adjustTime( double dt ) { offset_ -= dt;}
At start-up, the server will call clock->adjustTime(-clock->time()) to re-set it to 0. serverLogicalTime() would return clock->time() after that adjustment.
On Windows, you typically use QueryPerformanceCounter() instead -- although it has some bugs. In fact, all the PC hardware timers have bugs -- see this article.