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