clray
annotate src/timer.cc @ 62:d9520da6b801
minor readme fix
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Mon, 28 Dec 2015 10:31:58 +0200 |
parents | |
children |
rev | line source |
---|---|
nuclear@33 | 1 #include "timer.h" |
nuclear@33 | 2 |
nuclear@33 | 3 #if defined(unix) || defined(__unix__) || defined(__APPLE__) |
nuclear@33 | 4 #include <unistd.h> |
nuclear@33 | 5 #include <sys/time.h> |
nuclear@33 | 6 |
nuclear@33 | 7 long get_msec() |
nuclear@33 | 8 { |
nuclear@33 | 9 static struct timeval tv0; |
nuclear@33 | 10 struct timeval tv; |
nuclear@33 | 11 |
nuclear@33 | 12 gettimeofday(&tv, 0); |
nuclear@33 | 13 |
nuclear@33 | 14 if(tv0.tv_sec == 0 && tv0.tv_usec == 0) { |
nuclear@33 | 15 tv0 = tv; |
nuclear@33 | 16 return 0; |
nuclear@33 | 17 } |
nuclear@33 | 18 return (tv.tv_sec - tv0.tv_sec) * 1000L + (tv.tv_usec - tv0.tv_usec) / 1000L; |
nuclear@33 | 19 } |
nuclear@33 | 20 |
nuclear@33 | 21 #elif defined(WIN32) || defined(__WIN32__) |
nuclear@33 | 22 #include <windows.h> |
nuclear@33 | 23 |
nuclear@33 | 24 #pragma comment(lib, "winmm.lib") |
nuclear@33 | 25 |
nuclear@33 | 26 long get_msec() |
nuclear@33 | 27 { |
nuclear@33 | 28 return timeGetTime(); |
nuclear@33 | 29 } |
nuclear@33 | 30 #endif |