Top Up Prev Next Bottom Contents Index Search

12.3 Classes for interacting with the system clock

These classes provide simple means of interacting with the operating system's clock - sleeping until a specified time, timing events, etc. They may be replaced with something more general. Class TimeVal represents a time interval to microsecond precision. There are two constructors:

TimeVal();
TimeVal(double seconds);
The first represents a time interval of zero. In the second case, the seconds argument is rounded to the nearest microsecond. These classes rely on features found in BSD-based Unix systems and newer System V Unix systems. Older System V systems tend not to provide the ability to sleep for a time specified more accurately than a second.

operator double() const; 
This returns the interval value as a double.

TimeVal operator +(const TimeVal& arg) const;
TimeVal operator -(const TimeVal& arg) const;
TimeVal& operator +=(const TimeVal& arg);
TimeVal& operator -=(const TimeVal& arg);
These operators do simple addition and subtraction of TimeVals.

int operator >(const TimeVal& arg) const; 
int operator <(const TimeVal& arg) const;
These operators do simple comparisons of TimeVals.

Class Clock provides a simple interface to the system clock for measurement of actual elapsed time. It has an internal TimeVal field that represents the starting time of a time interval.

Clock(); 
The constructor creates a Clock with starting time equal to the time at which the constructor is executed.

void reset(); 
This method resets the start time to "now".

TimeVal elapsedTime() const; 
This method returns the elapsed time since the last reset or the call to the constructor.

int sleepUntil(const TimeVal& howLong) const; 
This method causes the process to sleep until howLong after the start time.



Top Up Prev Next Bottom Contents Index Search

Copyright © 1990-1997, University of California. All rights reserved.