00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef ACE_OS_NS_TIME_H
00018 # define ACE_OS_NS_TIME_H
00019
00020 # include "ace/pre.h"
00021
00022 # include "ace/config-all.h"
00023
00024 # if !defined (ACE_LACKS_PRAGMA_ONCE)
00025 # pragma once
00026 # endif
00027
00028 #include "ace/OS_NS_errno.h"
00029 #include "ace/Basic_Types.h"
00030 #include "ace/os_include/os_time.h"
00031 #include "ace/ACE_export.h"
00032
00033 #if defined (ACE_EXPORT_MACRO)
00034 # undef ACE_EXPORT_MACRO
00035 #endif
00036 #define ACE_EXPORT_MACRO ACE_Export
00037
00038 # if defined (ACE_HAS_BROKEN_R_ROUTINES)
00039 # undef ctime_r
00040 # undef asctime_r
00041 # endif
00042
00043 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00044
00045
00046 static const ACE_UINT32 ACE_U_ONE_SECOND_IN_MSECS = 1000U;
00047 static const ACE_UINT32 ACE_U_ONE_SECOND_IN_USECS = 1000000U;
00048 static const ACE_UINT32 ACE_U_ONE_SECOND_IN_NSECS = 1000000000U;
00049
00050 #if defined (ACE_LACKS_STRUCT_TM)
00051 struct tm {
00052 int tm_sec;
00053 int tm_min;
00054 int tm_hour;
00055 int tm_mday;
00056 int tm_mon;
00057 int tm_year;
00058 int tm_wday;
00059 int tm_yday;
00060 int tm_isdst;
00061 };
00062 #endif
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073 inline long ace_timezone()
00074 {
00075 #if defined (ACE_WIN32)
00076 TIME_ZONE_INFORMATION tz;
00077 GetTimeZoneInformation (&tz);
00078 return tz.Bias * 60;
00079 #elif defined (ACE_HAS_TIMEZONE)
00080
00081
00082 ::tzset();
00083 return timezone;
00084 #elif defined (ACE_HAS_TIMEZONE_GETTIMEOFDAY)
00085
00086
00087
00088 long result = 0;
00089 struct timeval time;
00090 struct timezone zone;
00091 ACE_UNUSED_ARG (result);
00092 ACE_OSCALL (::gettimeofday (&time, &zone), int, -1, result);
00093 return zone.tz_minuteswest * 60;
00094 #else
00095 ACE_NOTSUP_RETURN (0);
00096 #endif
00097 }
00098
00099
00100 #if !defined (ACE_LACKS_DIFFTIME)
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110 inline double ace_difftime(time_t t1, time_t t0)
00111 {
00112 return difftime (t1, t0);
00113 }
00114 #endif
00115
00116 # if defined (ACE_WIN32)
00117 # if !defined (ACE_LACKS_LONGLONG_T)
00118
00119 typedef unsigned __int64 ACE_QWORD;
00120 typedef unsigned __int64 ACE_hrtime_t;
00121 inline ACE_QWORD ACE_MAKE_QWORD (DWORD lo, DWORD hi) { return ACE_QWORD (lo) | (ACE_QWORD (hi) << 32); }
00122 inline DWORD ACE_LOW_DWORD (ACE_QWORD q) { return (DWORD) q; }
00123 inline DWORD ACE_HIGH_DWORD (ACE_QWORD q) { return (DWORD) (q >> 32); }
00124 # else
00125
00126 typedef ACE_UINT64 ACE_hrtime_t;
00127 # endif // ACE_LACKS_LONGLONG_T
00128 # elif defined (_TNS_R_TARGET)
00129 typedef long long ACE_hrtime_t;
00130 # else
00131 # if defined (ACE_HAS_HI_RES_TIMER) && !defined (ACE_LACKS_LONGLONG_T)
00132
00133 typedef hrtime_t ACE_hrtime_t;
00134 # else
00135 typedef ACE_UINT64 ACE_hrtime_t;
00136 # endif
00137 # endif
00138
00139 # if defined (ACE_LACKS_UNSIGNEDLONGLONG_T)
00140 # define ACE_HRTIME_CONVERSION(VAL) ACE_U64_TO_U32(VAL)
00141 # define ACE_HRTIME_TO_U64(VAL) ACE_U_LongLong(VAL)
00142 # else
00143 # define ACE_HRTIME_CONVERSION(VAL) (VAL)
00144 # define ACE_HRTIME_TO_U64(VAL) (VAL)
00145 # endif
00146
00147 namespace ACE_OS
00148 {
00149 enum ACE_HRTimer_Op
00150 {
00151 ACE_HRTIMER_START = 0x0,
00152 ACE_HRTIMER_INCR = 0x1,
00153 ACE_HRTIMER_STOP = 0x2,
00154 ACE_HRTIMER_GETTIME = 0xFFFF
00155 };
00156
00157
00158
00159 ACE_NAMESPACE_INLINE_FUNCTION
00160 char *asctime (const struct tm *tm);
00161
00162 ACE_NAMESPACE_INLINE_FUNCTION
00163 char *asctime_r (const struct tm *tm,
00164 char *buf, int buflen);
00165
00166 ACE_NAMESPACE_INLINE_FUNCTION
00167 int clock_gettime (clockid_t,
00168 struct timespec *);
00169
00170 ACE_NAMESPACE_INLINE_FUNCTION
00171 int clock_settime (clockid_t,
00172 const struct timespec *);
00173
00174 ACE_NAMESPACE_INLINE_FUNCTION
00175 ACE_TCHAR *ctime (const time_t *t);
00176
00177 #if defined (ACE_HAS_WINCE) && !defined (_DEBUG)
00178 extern ACE_EXPORT_MACRO
00179 #else
00180 ACE_NAMESPACE_INLINE_FUNCTION
00181 #endif
00182 ACE_TCHAR *ctime_r (const time_t *clock, ACE_TCHAR *buf, int buflen);
00183
00184 # if defined (difftime)
00185 # undef difftime
00186 # endif
00187
00188 #if !defined (ACE_LACKS_DIFFTIME)
00189 ACE_NAMESPACE_INLINE_FUNCTION
00190 #else
00191 extern ACE_Export
00192 #endif
00193 double difftime (time_t t1,
00194 time_t t0);
00195
00196 ACE_NAMESPACE_INLINE_FUNCTION
00197 ACE_hrtime_t gethrtime (const ACE_HRTimer_Op = ACE_HRTIMER_GETTIME);
00198
00199 ACE_NAMESPACE_INLINE_FUNCTION
00200 struct tm *gmtime (const time_t *clock);
00201
00202 ACE_NAMESPACE_INLINE_FUNCTION
00203 struct tm *gmtime_r (const time_t *clock,
00204 struct tm *res);
00205
00206 ACE_NAMESPACE_INLINE_FUNCTION
00207 struct tm *localtime (const time_t *clock);
00208
00209 extern ACE_Export
00210 struct tm *localtime_r (const time_t *clock,
00211 struct tm *res);
00212
00213
00214 extern ACE_Export
00215 time_t mktime (struct tm *timeptr);
00216
00217 ACE_NAMESPACE_INLINE_FUNCTION
00218 int nanosleep (const struct timespec *requested,
00219 struct timespec *remaining = 0);
00220
00221 # if defined (ACE_HAS_POWERPC_TIMER) && defined (ghs)
00222 extern ACE_Export
00223 void readPPCTimeBase (u_long &most,
00224 u_long &least);
00225 # endif
00226
00227 ACE_NAMESPACE_INLINE_FUNCTION
00228 size_t strftime (char *s,
00229 size_t maxsize,
00230 const char *format,
00231 const struct tm *timeptr);
00232
00233 ACE_NAMESPACE_INLINE_FUNCTION
00234 char *strptime (const char *buf,
00235 const char *format,
00236 struct tm *tm);
00237
00238 # if defined (ACE_LACKS_STRPTIME) && !defined (ACE_REFUSE_STRPTIME_EMULATION)
00239 extern ACE_Export
00240 char *strptime_emulation (const char *buf,
00241 const char *format,
00242 struct tm *tm);
00243
00244 extern ACE_Export
00245 int strptime_getnum (const char *buf, int *num, int *bi,
00246 int *fi, int min, int max);
00247 # endif
00248
00249 ACE_NAMESPACE_INLINE_FUNCTION
00250 time_t time (time_t *tloc = 0);
00251
00252 # if defined (timezone)
00253 # undef timezone
00254 # endif
00255
00256 ACE_NAMESPACE_INLINE_FUNCTION
00257 long timezone (void);
00258
00259
00260 ACE_NAMESPACE_INLINE_FUNCTION
00261 void tzset (void);
00262
00263
00264 }
00265
00266 ACE_END_VERSIONED_NAMESPACE_DECL
00267
00268 #if (defined (ACE_HAS_VERSIONED_NAMESPACE) \
00269 && ACE_HAS_VERSIONED_NAMESPACE == 1) \
00270 && defined (ghs) \
00271 && defined (ACE_HAS_PENTIUM) \
00272 && !defined (ACE_WIN32)
00273 #define ACE_GETHRTIME_NAME ACE_PREPROC_CONCATENATE(ACE_,ACE_PREPROC_CONCATENATE(ACE_VERSIONED_NAMESPACE_NAME, _gethrtime))
00274 #else
00275 # define ACE_GETHRTIME_NAME ACE_gethrtime
00276 #endif
00277
00278
00279 # if defined (ACE_HAS_INLINED_OSCALLS)
00280 # if defined (ACE_INLINE)
00281 # undef ACE_INLINE
00282 # endif
00283 # define ACE_INLINE inline
00284 # include "ace/OS_NS_time.inl"
00285 # endif
00286
00287 # include "ace/post.h"
00288 #endif