Fixed timing on weird systems.

This commit is contained in:
Thulinma 2012-09-18 16:37:50 +02:00
parent c019dc6e9f
commit 74312b2e51
3 changed files with 7 additions and 5 deletions

View file

@ -7,6 +7,8 @@
/// Sleeps for the indicated amount of milliseconds or longer.
void Util::sleep(int ms){
if (ms < 0){return;}
if (ms > 10000){return;}
struct timespec T;
T.tv_sec = ms/1000;
T.tv_nsec = 1000*(ms%1000);
@ -16,9 +18,9 @@ void Util::sleep(int ms){
/// Gets the current time in milliseconds.
long long int Util::getMS(){
/// \todo Possibly change to use clock_gettime - needs -lrt though...
timeval t;
gettimeofday(&t, 0);
return t.tv_sec * 1000 + t.tv_usec/1000;
struct timespec t;
clock_gettime(CLOCK_REALTIME, &t);
return ((long long int)t.tv_sec) * 1000 + t.tv_nsec/1000;
}
/// Gets the amount of seconds since 01/01/1970.