22 #if !defined(GLOBUS_TIME_H)
32 #define GLOBUS_I_TIME_INFINITY_SEC INT_MAX
33 #define GLOBUS_I_TIME_INFINITY_NSEC INT_MAX
34 #define GLOBUS_I_TIME_INFINITY_USEC INT_MAX
36 #if defined(_WIN32) && !defined(_POSIX)
37 typedef struct globus_abstime_s
43 typedef struct timespec globus_abstime_t;
46 typedef struct timeval globus_reltime_t;
51 #define GlobusTimeAbstimeSet(Abstime, Sec, USec) \
53 GlobusTimeAbstimeGetCurrent(Abstime); \
54 (Abstime).tv_nsec += (USec * 1000); \
55 if((Abstime).tv_nsec >= 1000000000) \
57 (Abstime).tv_sec += ((Abstime).tv_nsec / 1000000000);\
58 (Abstime).tv_nsec = (Abstime).tv_nsec % 1000000000; \
60 (Abstime).tv_sec += Sec; \
65 #define GlobusTimeAbstimeGet(Abstime, Sec, USec) \
67 Sec = (Abstime).tv_sec; \
68 USec = ((Abstime).tv_nsec / 1000); \
74 #define GlobusTimeReltimeSet(Reltime, Sec, USec) \
76 (Reltime).tv_usec = (USec); \
77 (Reltime).tv_sec = Sec; \
78 if((Reltime).tv_usec >= 1000000) \
80 (Reltime).tv_sec += ((Reltime).tv_usec / 1000000);\
81 (Reltime).tv_usec = (Reltime).tv_usec % 1000000; \
85 #define GlobusTimeReltimeGet(Reltime, Sec, USec) \
87 (USec) = (Reltime).tv_usec; \
88 (Sec) = (Reltime).tv_sec; \
91 #define GlobusTimeAbstimePrintf(Abstime) \
93 printf("sec -->%lu\n", (unsigned long) (Abstime).tv_sec); \
94 printf("nsec -->%lu\n", (unsigned long) (Abstime).tv_nsec); \
97 #define GlobusTimeReltimePrintf(Reltime) \
99 printf("sec -->%lu\n", (unsigned long) (Reltime).tv_sec); \
100 printf("usec -->%lu\n", (unsigned long) (Reltime).tv_usec); \
106 #define GlobusTimeAbstimeDiff(Reltime, T1, T2) \
108 int __res = globus_abstime_cmp(&(T1), &(T2)); \
111 (Reltime).tv_sec = (T2).tv_sec - (T1).tv_sec; \
112 (Reltime).tv_usec = \
113 (((T2).tv_nsec - (T1).tv_nsec) / 1000); \
114 if((Reltime).tv_usec < 0) \
116 (Reltime).tv_sec--; \
117 (Reltime).tv_usec += 1000000; \
122 (Reltime).tv_sec = (T1).tv_sec - (T2).tv_sec; \
123 (Reltime).tv_usec = \
124 (((T1).tv_nsec - (T2).tv_nsec) / 1000); \
125 if((Reltime).tv_usec < 0) \
127 (Reltime).tv_sec--; \
128 (Reltime).tv_usec += 1000000; \
133 (Reltime).tv_sec = 0; \
134 (Reltime).tv_usec = 0; \
138 #define GlobusTimeReltimeDiff(Reltime, T1, T2) \
140 int __res = globus_reltime_cmp(&(T1), &(T2)); \
143 (Reltime).tv_sec = (T2).tv_sec - (T1).tv_sec; \
144 (Reltime).tv_usec = \
145 ((T2).tv_usec - (T1).tv_usec); \
146 if((Reltime).tv_usec < 0) \
148 (Reltime).tv_sec--; \
149 (Reltime).tv_usec += 1000000; \
154 (Reltime).tv_sec = (T1).tv_sec - (T2).tv_sec; \
155 (Reltime).tv_usec = \
156 ((T1).tv_usec - (T2).tv_usec); \
157 if((Reltime).tv_usec < 0) \
159 (Reltime).tv_sec--; \
160 (Reltime).tv_usec += 1000000; \
165 (Reltime).tv_sec = 0; \
166 (Reltime).tv_usec = 0; \
173 #define GlobusTimeReltimeToUSec(SlpInt, Reltime) \
175 SlpInt = ((Reltime).tv_sec * 1000000) + \
176 ((Reltime).tv_usec); \
182 #define GlobusTimeReltimeToMilliSec( Milliseconds, Reltime) \
184 Milliseconds = ((Reltime).tv_sec * 1000) + \
185 ((Reltime).tv_usec)/ 1000; \
191 #define GlobusTimeAbstimeInc(Abstime, Reltime) \
193 (Abstime).tv_nsec += ((Reltime).tv_usec * 1000); \
194 if((Abstime).tv_nsec >= 1000000000) \
196 (Abstime).tv_sec++; \
197 (Abstime).tv_nsec -= 1000000000; \
199 (Abstime).tv_sec += (Reltime).tv_sec; \
202 #define GlobusTimeAbstimeDec(Abstime, Reltime) \
204 (Abstime).tv_nsec -= ((Reltime).tv_usec * 1000); \
205 if((Abstime).tv_nsec < 0) \
207 (Abstime).tv_sec--; \
208 (Abstime).tv_nsec += 1000000000; \
210 (Abstime).tv_sec -= (Reltime).tv_sec; \
218 # define GlobusTimeAbstimeGetCurrent(Abstime) \
220 struct _timeb timebuffer; \
222 _ftime(&timebuffer); \
223 (Abstime).tv_sec = timebuffer.time; \
224 (Abstime).tv_nsec = (timebuffer.millitm * 1000000); \
227 # define GlobusTimeAbstimeGetCurrent(Abstime) \
229 struct timeval __time; \
231 gettimeofday(&__time, GLOBUS_NULL); \
232 (Abstime).tv_sec = __time.tv_sec; \
233 (Abstime).tv_nsec = (__time.tv_usec * 1000); \
240 #define GlobusTimeAbstimeCopy(Dest, Src) \
242 (Dest).tv_sec = (Src).tv_sec; \
243 (Dest).tv_nsec = (Src).tv_nsec; \
249 #define GlobusTimeReltimeCopy(Dest, Src) \
251 (Dest).tv_sec = (Src).tv_sec; \
252 (Dest).tv_usec = (Src).tv_usec; \
258 #define GlobusTimeReltimeMultiply(Reltime, Factor) \
260 (Reltime).tv_usec *= Factor; \
261 (Reltime).tv_sec *= Factor; \
263 if((Reltime).tv_usec >= 1000000) \
265 (Reltime).tv_sec += ((Reltime).tv_usec / 1000000);\
266 (Reltime).tv_usec = (Reltime).tv_usec % 1000000; \
273 #define GlobusTimeReltimeDivide(Reltime, Factor) \
275 (Reltime).tv_usec /= Factor; \
276 (Reltime).tv_sec /= Factor; \
279 extern const globus_abstime_t globus_i_abstime_infinity;
280 extern const globus_abstime_t globus_i_abstime_zero;
281 extern const globus_reltime_t globus_i_reltime_infinity;
282 extern const globus_reltime_t globus_i_reltime_zero;
292 const globus_abstime_t * abstime);
299 const globus_abstime_t * abstime);
306 const globus_reltime_t * reltime);
320 const globus_abstime_t * abstime_1,
321 const globus_abstime_t * abstime_2);
335 const globus_reltime_t * reltime_1,
336 const globus_reltime_t * reltime_2);
int globus_reltime_cmp(const globus_reltime_t *reltime_1, const globus_reltime_t *reltime_2)
Definition: globus_time.c:131
globus_bool_t globus_time_has_expired(const globus_abstime_t *abstime)
Definition: globus_time.c:46
int globus_bool_t
Boolean type.
Definition: globus_types.h:93
globus_bool_t globus_time_reltime_is_infinity(const globus_reltime_t *reltime)
Definition: globus_time.c:75
int globus_abstime_cmp(const globus_abstime_t *abstime_1, const globus_abstime_t *abstime_2)
Definition: globus_time.c:88
globus_bool_t globus_time_abstime_is_infinity(const globus_abstime_t *abstime)
Definition: globus_time.c:62