Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / ace / OS_NS_time.h
blob615d591c424eef2dd71c785668e4728de9d3964b
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file OS_NS_time.h
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)
21 # 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
32 #endif
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
43 /**
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
49 * timezone.
51 inline long ace_timezone()
53 #if defined (ACE_WIN32)
54 TIME_ZONE_INFORMATION tz;
55 GetTimeZoneInformation (&tz);
56 return tz.Bias * 60;
57 #elif defined (ACE_HAS_TIMEZONE)
58 // The XPG/POSIX specification requires that tzset() be called to
59 // set the global variable <timezone>.
60 ::tzset();
61 return 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).
66 long result = 0;
67 struct timeval time;
68 struct timezone zone;
69 ACE_UNUSED_ARG (result);
70 ACE_OSCALL (::gettimeofday (&time, &zone), int, result);
71 return zone.tz_minuteswest * 60;
72 #else
73 ACE_NOTSUP_RETURN (0);
74 #endif
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);
88 # undef asctime_r
89 # else
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);
100 # undef gmtime_r
101 # else
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);
112 # undef localtime_r
113 # else
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
126 * it.
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)
149 namespace ACE_OS
151 enum ACE_HRTimer_Op
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,
170 struct timespec *);
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,
184 time_t t0);
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,
194 struct tm *res);
196 ACE_NAMESPACE_INLINE_FUNCTION
197 struct tm *localtime (const time_t *clock);
199 extern ACE_Export
200 struct tm *localtime_r (const time_t *clock,
201 struct tm *res);
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,
215 struct tm *res);
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,
222 struct tm *res);
223 #endif
226 // Get the current time.
227 extern ACE_Export
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,
236 size_t maxsize,
237 const char *format,
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
243 * zero
245 ACE_NAMESPACE_INLINE_FUNCTION
246 char *strptime (const char *buf,
247 const char *format,
248 struct tm *tm);
250 # if defined (ACE_LACKS_STRPTIME)
251 extern ACE_Export
252 char *strptime_emulation (const char *buf,
253 const char *format,
254 struct tm *tm);
256 extern ACE_Export
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
265 long timezone ();
267 // wrapper for time zone information.
268 ACE_NAMESPACE_INLINE_FUNCTION
269 void tzset ();
271 //@}
272 } /* namespace ACE_OS */
274 ACE_END_VERSIONED_NAMESPACE_DECL
276 #if (defined (ACE_HAS_VERSIONED_NAMESPACE) \
277 && ACE_HAS_VERSIONED_NAMESPACE == 1) \
278 && defined (ghs) \
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))
282 #else
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)
289 # undef 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 */