Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/gui/src/lib/util/timer.cc @ 7899

Last change on this file since 7899 was 7899, checked in by bensch, 18 years ago

gui: added timer class for a more exact time

File size: 635 bytes
Line 
1/**
2 * @file timer.cc
3 * @brief A Timer class, that handles all about time.
4 *
5 * code taken from audiere.
6 */
7
8#include "timer.h"
9
10
11#include <time.h>
12#include <sys/time.h>
13
14
15double Timer::getNow() {
16
17#if HAVE_CLOCK_GETTIME
18   // use the POSIX realtime clock to get the current time
19    struct timespec tp;
20    int result = clock_gettime(CLOCK_REALTIME, &tp);
21    if (result == 0) {
22      return tp.tv_sec * tp.tv_nsec / 1000000000.0;
23    }
24#endif
25
26    // can't use realtime clock!  Try to use gettimeofday
27    struct timeval tv;
28    gettimeofday(&tv, 0);
29    return tv.tv_sec + tv.tv_usec / 1000000.0;
30}
Note: See TracBrowser for help on using the repository browser.