3 //=============================================================================
7 * @author Douglas C. Schmidt <d.schmidt@vanderbilt.edu>
8 * @author Jesper S. M|ller<stophph@diku.dk>
9 * @author and a cast of thousands...
11 //=============================================================================
13 #ifndef ACE_OS_NS_TIME_H
14 # define ACE_OS_NS_TIME_H
16 # include /**/ "ace/pre.h"
18 # include "ace/config-all.h"
20 # if !defined (ACE_LACKS_PRAGMA_ONCE)
22 # endif /* ACE_LACKS_PRAGMA_ONCE */
24 #include "ace/Basic_Types.h"
25 #include "ace/os_include/os_time.h"
26 #include "ace/OS_NS_errno.h"
28 #include /**/ "ace/ACE_export.h"
30 #if defined (ACE_EXPORT_MACRO)
31 # undef ACE_EXPORT_MACRO
33 #define ACE_EXPORT_MACRO ACE_Export
35 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
37 // Type-safe, and unsigned.
38 static constexpr ACE_UINT32 ACE_U_ONE_SECOND_IN_MSECS
= 1000U;
39 static constexpr ACE_UINT32 ACE_U_ONE_SECOND_IN_USECS
= 1000000U;
40 static constexpr ACE_UINT32 ACE_U_ONE_SECOND_IN_NSECS
= 1000000000U;
42 /// Helper for the ACE_OS::timezone() function
44 * We put all the timezone stuff that used to be in ACE_OS::timezone()
45 * here because on some platforms "timezone" is a macro. Because of this,
46 * the name ACE_OS::timezone will cause errors. So in order to use the
47 * macro as it is defined but also keep the name ACE_OS::timezone, we
48 * use timezone first here in this inline function, and then undefine
51 inline long ace_timezone()
53 #if defined (ACE_WIN32)
54 TIME_ZONE_INFORMATION tz
;
55 GetTimeZoneInformation (&tz
);
57 #elif defined (ACE_HAS_TIMEZONE)
58 // The XPG/POSIX specification requires that tzset() be called to
59 // set the global variable <timezone>.
62 #elif defined (ACE_HAS_TIMEZONE_GETTIMEOFDAY)
63 // The XPG/POSIX specification does not require gettimeofday to
64 // set the timezone struct (it leaves the behavior of passing a
65 // non-null struct undefined).
69 ACE_UNUSED_ARG (result
);
70 ACE_OSCALL (::gettimeofday (&time
, &zone
), int, result
);
71 return zone
.tz_minuteswest
* 60;
73 ACE_NOTSUP_RETURN (0);
78 * We inline and undef some functions that may be implemented
79 * as macros on some platforms. This way macro definitions will
80 * be usable later as there is no way to save the macro definition
81 * using the pre-processor.
83 #if !defined (ACE_LACKS_ASCTIME_R)
84 inline char *ace_asctime_r_helper (const struct tm
*t
, char *buf
)
86 # if defined (asctime_r)
87 return asctime_r (t
, buf
);
90 return ACE_STD_NAMESPACE::asctime_r (t
, buf
);
91 # endif /* asctime_r */
93 #endif /* !ACE_LACKS_ASCTIME_R */
95 #if !defined (ACE_LACKS_GMTIME_R)
96 inline struct tm
*ace_gmtime_r_helper (const time_t *clock
, struct tm
*res
)
98 # if defined (gmtime_r)
99 return gmtime_r (clock
, res
);
102 return ACE_STD_NAMESPACE::gmtime_r (clock
, res
);
103 # endif /* gmtime_r */
105 #endif /* !ACE_LACKS_GMTIME_R */
107 #if !defined (ACE_LACKS_LOCALTIME_R)
108 inline struct tm
*ace_localtime_r_helper (const time_t *clock
, struct tm
*res
)
110 # if defined (localtime_r)
111 return localtime_r (clock
, res
);
114 return ACE_STD_NAMESPACE::localtime_r (clock
, res
);
115 # endif /* localtime_r */
117 #endif /* !ACE_LACKS_LOCALTIME_R */
119 /// Helper for the ACE_OS::difftime() function
121 * We moved the difftime code that used to be in ACE_OS::difftime()
122 * here because on some platforms "difftime" is a macro. Because of this,
123 * the name ACE_OS::difftime will cause errors. So in order to use the
124 * macro as it is defined but also keep the name ACE_OS::difftime, we
125 * use difftime first here in this inline function, and then undefine
128 inline double ace_difftime(time_t t1
, time_t t0
)
130 return difftime (t1
, t0
);
133 # if defined (ACE_WIN32)
134 typedef unsigned __int64 ACE_hrtime_t
;
135 # elif defined (_TNS_R_TARGET)
136 typedef long long ACE_hrtime_t
;
137 # else /* !ACE_WIN32 */
138 # if defined (ACE_HAS_HI_RES_TIMER)
139 /* hrtime_t is defined on systems (Suns) with ACE_HAS_HI_RES_TIMER */
140 typedef hrtime_t ACE_hrtime_t
;
141 # else /* ! ACE_HAS_HI_RES_TIMER */
142 typedef ACE_UINT64 ACE_hrtime_t
;
143 # endif /* ! ACE_HAS_HI_RES_TIMER */
144 # endif /* ACE_WIN32 */
146 #define ACE_HRTIME_CONVERSION(VAL) (VAL)
147 #define ACE_HRTIME_TO_U64(VAL) (VAL)
153 ACE_HRTIMER_START
= 0x0, // Only use these if you can stand
154 ACE_HRTIMER_INCR
= 0x1, // for interrupts to be disabled during
155 ACE_HRTIMER_STOP
= 0x2, // the timed interval!!!!
156 ACE_HRTIMER_GETTIME
= 0xFFFF
159 //@{ @name A set of wrappers for operations on time.
161 ACE_NAMESPACE_INLINE_FUNCTION
162 char *asctime (const struct tm
*tm
);
164 ACE_NAMESPACE_INLINE_FUNCTION
165 char *asctime_r (const struct tm
*tm
,
166 char *buf
, int buflen
);
168 ACE_NAMESPACE_INLINE_FUNCTION
169 int clock_gettime (clockid_t
,
172 ACE_NAMESPACE_INLINE_FUNCTION
173 int clock_settime (clockid_t
,
174 const struct timespec
*);
176 ACE_NAMESPACE_INLINE_FUNCTION
177 ACE_TCHAR
*ctime (const time_t *t
);
179 ACE_NAMESPACE_INLINE_FUNCTION
180 ACE_TCHAR
*ctime_r (const time_t *clock
, ACE_TCHAR
*buf
, int buflen
);
182 ACE_NAMESPACE_INLINE_FUNCTION
183 double difftime (time_t t1
,
186 ACE_NAMESPACE_INLINE_FUNCTION
187 ACE_hrtime_t
gethrtime (const ACE_HRTimer_Op
= ACE_HRTIMER_GETTIME
);
189 ACE_NAMESPACE_INLINE_FUNCTION
190 struct tm
*gmtime (const time_t *clock
);
192 ACE_NAMESPACE_INLINE_FUNCTION
193 struct tm
*gmtime_r (const time_t *clock
,
196 ACE_NAMESPACE_INLINE_FUNCTION
197 struct tm
*localtime (const time_t *clock
);
200 struct tm
*localtime_r (const time_t *clock
,
203 #if defined (ACE_USES_ULONG_FOR_STAT_TIME)
204 ACE_NAMESPACE_INLINE_FUNCTION
205 ACE_TCHAR
*ctime (const unsigned long *t
);
207 ACE_NAMESPACE_INLINE_FUNCTION
208 ACE_TCHAR
*ctime_r (const unsigned long *clock
, ACE_TCHAR
*buf
, int buflen
);
210 ACE_NAMESPACE_INLINE_FUNCTION
211 struct tm
*gmtime (const unsigned long *clock
);
213 ACE_NAMESPACE_INLINE_FUNCTION
214 struct tm
*gmtime_r (const unsigned long *clock
,
217 ACE_NAMESPACE_INLINE_FUNCTION
218 struct tm
*localtime (const unsigned long *clock
);
220 ACE_NAMESPACE_INLINE_FUNCTION
221 struct tm
*localtime_r (const unsigned long *clock
,
226 // Get the current time.
228 time_t mktime (struct tm
*timeptr
);
230 ACE_NAMESPACE_INLINE_FUNCTION
231 int nanosleep (const struct timespec
*requested
,
232 struct timespec
*remaining
= 0);
234 ACE_NAMESPACE_INLINE_FUNCTION
235 size_t strftime (char *s
,
238 const struct tm
*timeptr
)
239 ACE_GCC_FORMAT_ATTRIBUTE (strftime
, 3, 0);
242 * strptime wrapper. Note that the struct @a tm will always be set to
245 ACE_NAMESPACE_INLINE_FUNCTION
246 char *strptime (const char *buf
,
250 # if defined (ACE_LACKS_STRPTIME)
252 char *strptime_emulation (const char *buf
,
257 int strptime_getnum (const char *buf
, int *num
, int *bi
,
258 int *fi
, int min
, int max
);
259 # endif /* ACE_LACKS_STRPTIME */
261 ACE_NAMESPACE_INLINE_FUNCTION
262 time_t time (time_t *tloc
= 0);
264 ACE_NAMESPACE_INLINE_FUNCTION
267 // wrapper for time zone information.
268 ACE_NAMESPACE_INLINE_FUNCTION
272 } /* namespace ACE_OS */
274 ACE_END_VERSIONED_NAMESPACE_DECL
276 #if (defined (ACE_HAS_VERSIONED_NAMESPACE) \
277 && ACE_HAS_VERSIONED_NAMESPACE == 1) \
279 && defined (ACE_HAS_PENTIUM) \
280 && !defined (ACE_WIN32)
281 #define ACE_GETHRTIME_NAME ACE_PREPROC_CONCATENATE(ACE_,ACE_PREPROC_CONCATENATE(ACE_VERSIONED_NAMESPACE_NAME, _gethrtime))
283 # define ACE_GETHRTIME_NAME ACE_gethrtime
284 #endif /* ACE_HAS_VERSIONED_NAMESPACE == 1 */
287 # if defined (ACE_HAS_INLINED_OSCALLS)
288 # if defined (ACE_INLINE)
290 # endif /* ACE_INLINE */
291 # define ACE_INLINE inline
292 # include "ace/OS_NS_time.inl"
293 # endif /* ACE_HAS_INLINED_OSCALLS */
295 # include /**/ "ace/post.h"
296 #endif /* ACE_OS_NS_TIME_H */