1 #ifndef SimTK_SimTKCOMMON_TIMING_H_
2 #define SimTK_SimTKCOMMON_TIMING_H_
64 #ifndef HAVE_STRUCT_TIMESPEC
65 #define HAVE_STRUCT_TIMESPEC 1
87 typedef unsigned int useconds_t;
88 inline int usleep(useconds_t us) {
90 req.tv_sec = (long) (us / 1000000U);
91 req.tv_nsec = (long)((us % 1000000U)*1000U);
92 int status = nanosleep(&req,0);
93 return status ? -1 : 0;
97 #if defined(_MSC_VER) || defined(__APPLE__)
99 typedef long clockid_t;
110 #define CLOCK_REALTIME 1 // time of day clock, from 1/1/1970
111 #define CLOCK_MONOTONIC 2 // counter from last boot time
112 #define CLOCK_MONOTONIC_HR 3 // "high resolution" (same)
113 #define CLOCK_MONOTONIC_RAW 4 // "not subject to NTP adjustments" (same)
114 #define CLOCK_THREAD_CPUTIME_ID 5 // current thread's cpu time (kernel+user)
115 #define CLOCK_PROCESS_CPUTIME_ID 6 // cumulative cpu time of all threads of
122 struct timespec *tp);
156 {
return (
long long)ts.tv_sec*1000000000LL + (
long long)ts.tv_nsec; }
161 { ts.tv_sec = (long)(ns / 1000000000LL);
162 if (ns >= 0) ts.tv_nsec = (long)( ns % 1000000000LL);
163 else ts.tv_nsec = -(long)((-ns) % 1000000000LL); }
199 clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts);
210 clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts);
244 #ifdef CLOCK_MONOTONIC_RAW
245 clock_gettime(CLOCK_MONOTONIC_RAW, &ts);
247 clock_gettime(CLOCK_MONOTONIC, &ts);
285 #endif // SimTK_SimTKCOMMON_TIMING_H_