| 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 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
#include <sys/time.h> |
| 31 |
|
| 32 |
#ifdef WIN32 |
| 33 |
#include <windows.h> |
| 34 |
#endif |
| 35 |
|
| 36 |
typedef double Real; |
| 37 |
|
| 38 |
#ifdef WIN32 |
| 39 |
#define UPDATE_TICKER(a,b,c,d,e) updateTicker(a,b,c,d,e) |
| 40 |
|
| 41 |
|
| 42 |
#define GET_TIME_OF_DAY(a,b,c,d,e,f,g) gettimeofday(a,b,c,d,e,f,g) |
| 43 |
|
| 44 |
|
| 45 |
#define TSTART(a,b,c,d,e,f) tstart(a,b,c,d,e,f) |
| 46 |
|
| 47 |
|
| 48 |
#define RETRIEVE_SEC(a) a |
| 49 |
#endif |
| 50 |
|
| 51 |
#ifdef UNIX |
| 52 |
#define UPDATE_TICKER(a,b,c,d,e) updateTicker(a) |
| 53 |
|
| 54 |
#define GET_TIME_OF_DAY(a,b,c,d,e,f,g) gettimeofday(a,NULL) |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
#define TSTART(a,b,c,d,e,f) |
| 59 |
|
| 60 |
|
| 61 |
#define RETRIEVE_SEC(a) a%86400L |
| 62 |
|
| 63 |
#endif |
| 64 |
|
| 65 |
struct TTicker { |
| 66 |
Real count; |
| 67 |
struct timeval lastTime; |
| 68 |
}; |
| 69 |
|
| 70 |
#ifdef WIN32 |
| 71 |
|
| 72 |
extern LARGE_INTEGER freq; |
| 73 |
#endif |
| 74 |
|
| 75 |
#ifdef WIN32 |
| 76 |
|
| 77 |
int tstart(LARGE_INTEGER & _tstart, unsigned long &secs, unsigned long &msecs, |
| 78 |
int &first, BYTE meter, int flag); |
| 79 |
|
| 80 |
|
| 81 |
int gettimeofday(struct timeval *thisTime, LARGE_INTEGER & _tend, LARGE_INTEGER & _tstart, |
| 82 |
unsigned long &secs, unsigned long &msecs, BYTE meter, int flag); |
| 83 |
|
| 84 |
|
| 85 |
void updateTicker(struct TTicker *Ticker, LARGE_INTEGER & _tend, LARGE_INTEGER & _tprec, |
| 86 |
LARGE_INTEGER & _tstart, int &first); |
| 87 |
#endif |
| 88 |
|
| 89 |
|
| 90 |
void setSeedRandom(); |
| 91 |
|
| 92 |
#ifdef UNIX |
| 93 |
|
| 94 |
void updateTicker(struct TTicker *Ticker); |
| 95 |
#endif |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
inline int timeval_subtract (struct timeval *result,const struct timeval a,const struct timeval b) |
| 100 |
{ |
| 101 |
timeval x,y; |
| 102 |
|
| 103 |
x=a; |
| 104 |
y=b; |
| 105 |
|
| 106 |
|
| 107 |
if (x.tv_usec < y.tv_usec) { |
| 108 |
int nsec = (y.tv_usec - x.tv_usec) / 1000000 + 1; |
| 109 |
y.tv_usec -= 1000000 * nsec; |
| 110 |
y.tv_sec += nsec; |
| 111 |
} |
| 112 |
if (x.tv_usec - y.tv_usec > 1000000) { |
| 113 |
int nsec = (y.tv_usec - x.tv_usec) / 1000000; |
| 114 |
y.tv_usec += 1000000 * nsec; |
| 115 |
y.tv_sec -= nsec; |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
result->tv_sec = x.tv_sec - y.tv_sec; |
| 120 |
result->tv_usec = x.tv_usec - y.tv_usec; |
| 121 |
|
| 122 |
|
| 123 |
return x.tv_sec < y.tv_sec; |
| 124 |
} |
| 125 |
|