Use clock_gettime instead of gettimeofday as recommended by QNX.

This commit is contained in:
Sacha 2013-10-25 14:13:27 +10:00
parent 46dfa25ca4
commit b9ba2f27ac
2 changed files with 11 additions and 2 deletions

View File

@ -206,11 +206,14 @@ public:
// mtx.lock();
#else
timespec timeout;
#ifdef __APPLE__
timeval tv;
gettimeofday(&tv, NULL);
timeout.tv_sec = tv.tv_sec;
timeout.tv_nsec = tv.tv_usec * 1000;
#else
clock_gettime(CLOCK_REALTIME, &timeout);
#endif
timeout.tv_sec += milliseconds / 1000;
timeout.tv_nsec += milliseconds * 1000000;
pthread_mutex_lock(&mtx.native_handle());

View File

@ -21,7 +21,7 @@ static float curtime_f = 0;
__int64 _frequency = 0;
__int64 _starttime = 0;
double real_time_now(){
double real_time_now() {
if (_frequency == 0) {
QueryPerformanceFrequency((LARGE_INTEGER*)&_frequency);
QueryPerformanceCounter((LARGE_INTEGER*)&_starttime);
@ -32,6 +32,12 @@ double real_time_now(){
return ((double) (time - _starttime) / (double) _frequency);
}
#elif defined(BLACKBERRY)
double real_time_now() {
struct timespec time;
clock_gettime(CLOCK_MONOTONIC, &time); // Linux must use CLOCK_MONOTONIC_RAW due to time warps
return time.tv_sec + time.tv_nsec / 1.0e9;
}
#else
uint64_t _frequency = 0;