summaryrefslogtreecommitdiff
path: root/src/timer_posix.cpp
blob: 20681bd78724d416cc793e19ae3ec1fce13a5db6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <time.h>
#include <sys/time.h>
#include "timer.h"
#include "types.h"


namespace audiere {

  u64 GetNow() {

#if HAVE_CLOCK_GETTIME
    // use the POSIX realtime clock to get the current time
    struct timespec tp;
    int result = clock_gettime(CLOCK_REALTIME, &tp);
    if (result == 0) {
      return u64(tp.tv_sec) * 1000000 + u64(tp.tv_nsec) / 1000;
    }
#endif

    // can't use realtime clock!  Try to use gettimeofday
    struct timeval tv;
    gettimeofday(&tv, 0);
    return u64(tv.tv_sec) * 1000000 + tv.tv_usec;
  }

}