OS_NS_time.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file   OS_NS_time.h
00006  *
00007  *  OS_NS_time.h,v 1.19 2006/06/20 20:27:41 shuston Exp
00008  *
00009  *  @author Douglas C. Schmidt <schmidt@cs.wustl.edu>
00010  *  @author Jesper S. M|ller<stophph@diku.dk>
00011  *  @author and a cast of thousands...
00012  *
00013  *  Originally in OS.h.
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 /* ACE_LACKS_PRAGMA_ONCE */
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 /* ACE_HAS_BROKEN_R_ROUTINES */
00042 
00043 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00044 
00045 // Type-safe, and unsigned.
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 // WinCE prior to Visual Studio 2005 integration doesn't have most of
00052 // the standard C library time functions. It also doesn't define struct tm.
00053 // SYSTEMTIME has pretty much the same info though, so we can map it when
00054 // needed. Define struct tm here and use it when needed. This is taken
00055 // from the standard C library.
00056 struct tm {
00057   int tm_sec;
00058   int tm_min;
00059   int tm_hour;
00060   int tm_mday;      // Day of the month
00061   int tm_mon;
00062   int tm_year;
00063   int tm_wday;      // Day of the week
00064   int tm_yday;      // Day in the year
00065   int tm_isdst;     // >0 if dst in effet; 0 if not; <0 if unknown
00066 };
00067 #endif /* ACE_HAS_WINCE */
00068 
00069 /// Helper for the ACE_OS::timezone() function
00070 /**
00071  * We put all the timezone stuff that used to be in ACE_OS::timezone()
00072  * here because on some platforms "timezone" is a macro.  Because of this,
00073  * the name ACE_OS::timezone will cause errors.  So in order to use the
00074  * macro as it is defined but also keep the name ACE_OS::timezone, we
00075  * use timezone first here in this inline function, and then undefine
00076  * timezone.
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;  // For Win32.
00086 #elif defined (ACE_WIN32) && defined (ACE_HAS_DINKUM_STL)
00087   time_t tod = time(0);   // get current time
00088   time_t t1 = mktime(gmtime(&tod));   // convert without timezone
00089   time_t t2 = mktime(localtime(&tod));   // convert with timezone
00090   return difftime(t1, t2); // compute difference in seconds
00091 #elif defined (ACE_HAS_TIMEZONE)
00092   // The XPG/POSIX specification requires that tzset() be called to
00093   // set the global variable <timezone>.
00094   ::tzset();
00095   return timezone;
00096 #elif defined (ACE_HAS_TIMEZONE_GETTIMEOFDAY)
00097   // The XPG/POSIX specification does not require gettimeofday to
00098   // set the timezone struct (it leaves the behavior of passing a
00099   // non-null struct undefined).
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 /// Helper for the ACE_OS::difftime() function
00114 /**
00115  * We moved the difftime code that used to be in ACE_OS::difftime()
00116  * here because on some platforms "difftime" is a macro.  Because of this,
00117  * the name ACE_OS::difftime will cause errors.  So in order to use the
00118  * macro as it is defined but also keep the name ACE_OS::difftime, we
00119  * use difftime first here in this inline function, and then undefine
00120  * it.
00121  */
00122 inline double ace_difftime(time_t t1, time_t t0)
00123 {
00124   return difftime (t1, t0);
00125 }
00126 #endif /* !ACE_LACKS_DIFFTIME */
00127 
00128 # if defined (ACE_WIN32)
00129 #   if !defined (ACE_LACKS_LONGLONG_T)
00130 // 64-bit quad-word definitions.
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 // Can't find ANY place that ACE_QWORD is used, but hrtime_t is.
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 /* !ACE_WIN32 */
00143 #   if defined (ACE_HAS_HI_RES_TIMER) &&  !defined (ACE_LACKS_LONGLONG_T)
00144   /* hrtime_t is defined on systems (Suns) with ACE_HAS_HI_RES_TIMER */
00145   typedef hrtime_t ACE_hrtime_t;
00146 #   else  /* ! ACE_HAS_HI_RES_TIMER  ||  ACE_LACKS_LONGLONG_T */
00147   typedef ACE_UINT64 ACE_hrtime_t;
00148 #   endif /* ! ACE_HAS_HI_RES_TIMER  ||  ACE_LACKS_LONGLONG_T */
00149 # endif /* ACE_WIN32 */
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,  // Only use these if you can stand
00164       ACE_HRTIMER_INCR = 0x1,   // for interrupts to be disabled during
00165       ACE_HRTIMER_STOP = 0x2,   // the timed interval!!!!
00166       ACE_HRTIMER_GETTIME = 0xFFFF
00167     };
00168 
00169   //@{ @name A set of wrappers for operations on time.
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 /* difftime */
00199 
00200 #if !defined (ACE_LACKS_DIFFTIME)
00201   ACE_NAMESPACE_INLINE_FUNCTION
00202 #else
00203   extern ACE_Export
00204 #endif /* ! ACE_LACKS_DIFFTIME */
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   // Get the current time.
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 /* ACE_HAS_POWERPC_TIMER && ghs */
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 /* ACE_LACKS_STRPTIME && !ACE_REFUSE_STRPTIME_EMULATION */
00260 
00261   ACE_NAMESPACE_INLINE_FUNCTION
00262   time_t time (time_t *tloc = 0);
00263 
00264 # if defined (timezone)
00265 #   undef timezone
00266 # endif /* timezone */
00267 
00268   ACE_NAMESPACE_INLINE_FUNCTION
00269   long timezone (void);
00270 
00271   // wrapper for time zone information.
00272   ACE_NAMESPACE_INLINE_FUNCTION
00273   void tzset (void);
00274 
00275   //@}
00276 } /* namespace ACE_OS */
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  /* ACE_HAS_VERSIONED_NAMESPACE == 1 */
00289 
00290 
00291 # if defined (ACE_HAS_INLINED_OSCALLS)
00292 #   if defined (ACE_INLINE)
00293 #     undef ACE_INLINE
00294 #   endif /* ACE_INLINE */
00295 #   define ACE_INLINE inline
00296 #   include "ace/OS_NS_time.inl"
00297 # endif /* ACE_HAS_INLINED_OSCALLS */
00298 
00299 # include /**/ "ace/post.h"
00300 #endif /* ACE_OS_NS_TIME_H */

Generated on Thu Nov 9 09:41:58 2006 for ACE by doxygen 1.3.6