3 //=============================================================================
7 * $Id: OS_NS_time.h 80826 2008-03-04 14:51:23Z wotte $
9 * @author Douglas C. Schmidt <schmidt@cs.wustl.edu>
10 * @author Jesper S. M|ller<stophph@diku.dk>
11 * @author and a cast of thousands...
15 //=============================================================================
17 #ifndef ACE_OS_NS_TIME_H
18 # define ACE_OS_NS_TIME_H
20 # include /**/ "ace/pre.h"
22 # include "ace/config-all.h"
24 # if !defined (ACE_LACKS_PRAGMA_ONCE)
26 # endif /* ACE_LACKS_PRAGMA_ONCE */
28 #include "ace/OS_NS_errno.h"
29 #include "ace/Basic_Types.h"
30 #include "ace/os_include/os_time.h"
31 #include /**/ "ace/ACE_export.h"
33 #if defined (ACE_EXPORT_MACRO)
34 # undef ACE_EXPORT_MACRO
36 #define ACE_EXPORT_MACRO ACE_Export
38 # if defined (ACE_HAS_BROKEN_R_ROUTINES)
41 # endif /* ACE_HAS_BROKEN_R_ROUTINES */
43 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
45 // Type-safe, and unsigned.
46 static const ACE_UINT32 ACE_U_ONE_SECOND_IN_MSECS
= 1000U;
47 static const ACE_UINT32 ACE_U_ONE_SECOND_IN_USECS
= 1000000U;
48 static const ACE_UINT32 ACE_U_ONE_SECOND_IN_NSECS
= 1000000000U;
50 #if defined (ACE_LACKS_STRUCT_TM)
55 int tm_mday
; // Day of the month
58 int tm_wday
; // Day of the week
59 int tm_yday
; // Day in the year
60 int tm_isdst
; // >0 if dst in effet; 0 if not; <0 if unknown
62 #endif /* ACE_LACKS_STRUCT_TM */
64 /// Helper for the ACE_OS::timezone() function
66 * We put all the timezone stuff that used to be in ACE_OS::timezone()
67 * here because on some platforms "timezone" is a macro. Because of this,
68 * the name ACE_OS::timezone will cause errors. So in order to use the
69 * macro as it is defined but also keep the name ACE_OS::timezone, we
70 * use timezone first here in this inline function, and then undefine
73 inline long ace_timezone()
75 #if defined (ACE_WIN32)
76 TIME_ZONE_INFORMATION tz
;
77 GetTimeZoneInformation (&tz
);
79 #elif defined (ACE_HAS_TIMEZONE)
80 // The XPG/POSIX specification requires that tzset() be called to
81 // set the global variable <timezone>.
84 #elif defined (ACE_HAS_TIMEZONE_GETTIMEOFDAY)
85 // The XPG/POSIX specification does not require gettimeofday to
86 // set the timezone struct (it leaves the behavior of passing a
87 // non-null struct undefined).
91 ACE_UNUSED_ARG (result
);
92 ACE_OSCALL (::gettimeofday (&time
, &zone
), int, -1, result
);
93 return zone
.tz_minuteswest
* 60;
95 ACE_NOTSUP_RETURN (0);
100 #if !defined (ACE_LACKS_DIFFTIME)
101 /// Helper for the ACE_OS::difftime() function
103 * We moved the difftime code that used to be in ACE_OS::difftime()
104 * here because on some platforms "difftime" is a macro. Because of this,
105 * the name ACE_OS::difftime will cause errors. So in order to use the
106 * macro as it is defined but also keep the name ACE_OS::difftime, we
107 * use difftime first here in this inline function, and then undefine
110 inline double ace_difftime(time_t t1
, time_t t0
)
112 return difftime (t1
, t0
);
114 #endif /* !ACE_LACKS_DIFFTIME */
116 # if defined (ACE_WIN32)
117 # if !defined (ACE_LACKS_LONGLONG_T)
118 // 64-bit quad-word definitions.
119 typedef unsigned __int64 ACE_QWORD
;
120 typedef unsigned __int64 ACE_hrtime_t
;
121 inline ACE_QWORD
ACE_MAKE_QWORD (DWORD lo
, DWORD hi
) { return ACE_QWORD (lo
) | (ACE_QWORD (hi
) << 32); }
122 inline DWORD
ACE_LOW_DWORD (ACE_QWORD q
) { return (DWORD
) q
; }
123 inline DWORD
ACE_HIGH_DWORD (ACE_QWORD q
) { return (DWORD
) (q
>> 32); }
125 // Can't find ANY place that ACE_QWORD is used, but hrtime_t is.
126 typedef ACE_UINT64 ACE_hrtime_t
;
127 # endif // ACE_LACKS_LONGLONG_T
128 # elif defined (_TNS_R_TARGET)
129 typedef long long ACE_hrtime_t
;
130 # else /* !ACE_WIN32 */
131 # if defined (ACE_HAS_HI_RES_TIMER) && !defined (ACE_LACKS_LONGLONG_T)
132 /* hrtime_t is defined on systems (Suns) with ACE_HAS_HI_RES_TIMER */
133 typedef hrtime_t ACE_hrtime_t
;
134 # else /* ! ACE_HAS_HI_RES_TIMER || ACE_LACKS_LONGLONG_T */
135 typedef ACE_UINT64 ACE_hrtime_t
;
136 # endif /* ! ACE_HAS_HI_RES_TIMER || ACE_LACKS_LONGLONG_T */
137 # endif /* ACE_WIN32 */
139 # if defined (ACE_LACKS_UNSIGNEDLONGLONG_T)
140 # define ACE_HRTIME_CONVERSION(VAL) ACE_U64_TO_U32(VAL)
141 # define ACE_HRTIME_TO_U64(VAL) ACE_U_LongLong(VAL)
143 # define ACE_HRTIME_CONVERSION(VAL) (VAL)
144 # define ACE_HRTIME_TO_U64(VAL) (VAL)
151 ACE_HRTIMER_START
= 0x0, // Only use these if you can stand
152 ACE_HRTIMER_INCR
= 0x1, // for interrupts to be disabled during
153 ACE_HRTIMER_STOP
= 0x2, // the timed interval!!!!
154 ACE_HRTIMER_GETTIME
= 0xFFFF
157 //@{ @name A set of wrappers for operations on time.
159 ACE_NAMESPACE_INLINE_FUNCTION
160 char *asctime (const struct tm
*tm
);
162 ACE_NAMESPACE_INLINE_FUNCTION
163 char *asctime_r (const struct tm
*tm
,
164 char *buf
, int buflen
);
166 ACE_NAMESPACE_INLINE_FUNCTION
167 int clock_gettime (clockid_t
,
170 ACE_NAMESPACE_INLINE_FUNCTION
171 int clock_settime (clockid_t
,
172 const struct timespec
*);
174 ACE_NAMESPACE_INLINE_FUNCTION
175 ACE_TCHAR
*ctime (const time_t *t
);
177 #if defined (ACE_HAS_WINCE) && !defined (_DEBUG)
178 extern ACE_EXPORT_MACRO
180 ACE_NAMESPACE_INLINE_FUNCTION
182 ACE_TCHAR
*ctime_r (const time_t *clock
, ACE_TCHAR
*buf
, int buflen
);
184 # if defined (difftime)
186 # endif /* difftime */
188 #if !defined (ACE_LACKS_DIFFTIME)
189 ACE_NAMESPACE_INLINE_FUNCTION
192 #endif /* ! ACE_LACKS_DIFFTIME */
193 double difftime (time_t t1
,
196 ACE_NAMESPACE_INLINE_FUNCTION
197 ACE_hrtime_t
gethrtime (const ACE_HRTimer_Op
= ACE_HRTIMER_GETTIME
);
199 ACE_NAMESPACE_INLINE_FUNCTION
200 struct tm
*gmtime (const time_t *clock
);
202 ACE_NAMESPACE_INLINE_FUNCTION
203 struct tm
*gmtime_r (const time_t *clock
,
206 ACE_NAMESPACE_INLINE_FUNCTION
207 struct tm
*localtime (const time_t *clock
);
210 struct tm
*localtime_r (const time_t *clock
,
213 // Get the current time.
215 time_t mktime (struct tm
*timeptr
);
217 ACE_NAMESPACE_INLINE_FUNCTION
218 int nanosleep (const struct timespec
*requested
,
219 struct timespec
*remaining
= 0);
221 # if defined (ACE_HAS_POWERPC_TIMER) && defined (ghs)
223 void readPPCTimeBase (u_long
&most
,
225 # endif /* ACE_HAS_POWERPC_TIMER && ghs */
227 ACE_NAMESPACE_INLINE_FUNCTION
228 size_t strftime (char *s
,
231 const struct tm
*timeptr
);
233 ACE_NAMESPACE_INLINE_FUNCTION
234 char *strptime (const char *buf
,
238 # if defined (ACE_LACKS_STRPTIME) && !defined (ACE_REFUSE_STRPTIME_EMULATION)
240 char *strptime_emulation (const char *buf
,
245 int strptime_getnum (const char *buf
, int *num
, int *bi
,
246 int *fi
, int min
, int max
);
247 # endif /* ACE_LACKS_STRPTIME && !ACE_REFUSE_STRPTIME_EMULATION */
249 ACE_NAMESPACE_INLINE_FUNCTION
250 time_t time (time_t *tloc
= 0);
252 # if defined (timezone)
254 # endif /* timezone */
256 ACE_NAMESPACE_INLINE_FUNCTION
257 long timezone (void);
259 // wrapper for time zone information.
260 ACE_NAMESPACE_INLINE_FUNCTION
264 } /* namespace ACE_OS */
266 ACE_END_VERSIONED_NAMESPACE_DECL
268 #if (defined (ACE_HAS_VERSIONED_NAMESPACE) \
269 && ACE_HAS_VERSIONED_NAMESPACE == 1) \
271 && defined (ACE_HAS_PENTIUM) \
272 && !defined (ACE_WIN32)
273 #define ACE_GETHRTIME_NAME ACE_PREPROC_CONCATENATE(ACE_,ACE_PREPROC_CONCATENATE(ACE_VERSIONED_NAMESPACE_NAME, _gethrtime))
275 # define ACE_GETHRTIME_NAME ACE_gethrtime
276 #endif /* ACE_HAS_VERSIONED_NAMESPACE == 1 */
279 # if defined (ACE_HAS_INLINED_OSCALLS)
280 # if defined (ACE_INLINE)
282 # endif /* ACE_INLINE */
283 # define ACE_INLINE inline
284 # include "ace/OS_NS_time.inl"
285 # endif /* ACE_HAS_INLINED_OSCALLS */
287 # include /**/ "ace/post.h"
288 #endif /* ACE_OS_NS_TIME_H */