Debian Codegraph @

src/common/timestamp.h

raw symbols SCIP
1 /*
2 * Component of the D-ITG 2.8.1 (r1023) platform (http://traffic.comics.unina.it/software/ITG)
3 *
4 * Copyright : (C) 2004-2013 by Alessio Botta, Walter de Donato, Alberto Dainotti,
5 * Stefano Avallone, Antonio Pescape' (PI)
6 * COMICS (COMputer for Interaction and CommunicationS) Group
7 * Department of Electrical Engineering and Information Technologies
8 * University of Napoli "Federico II".
9 * email : [email protected], [email protected], [email protected],
10 * [email protected], [email protected]
11 *
12 * This program is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation, either version 3 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 *
25 * For commercial use please refer to D-ITG Professional.
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