OS_NS_time.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file   OS_NS_time.h
00006  *
00007  *  $Id: OS_NS_time.h 78120 2007-04-19 14:30:17Z schmidt $
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_WIN32)
00081   TIME_ZONE_INFORMATION tz;
00082   GetTimeZoneInformation (&tz);
00083   return tz.Bias * 60;
00084 #elif defined (ACE_HAS_TIMEZONE)
00085   // The XPG/POSIX specification requires that tzset() be called to
00086   // set the global variable <timezone>.
00087   ::tzset();
00088   return timezone;
00089 #elif defined (ACE_HAS_TIMEZONE_GETTIMEOFDAY)
00090   // The XPG/POSIX specification does not require gettimeofday to
00091   // set the timezone struct (it leaves the behavior of passing a
00092   // non-null struct undefined).
00093   long result = 0;
00094   struct timeval time;
00095   struct timezone zone;
00096   ACE_UNUSED_ARG (result);
00097   ACE_OSCALL (::gettimeofday (&time, &zone), int, -1, result);
00098   return zone.tz_minuteswest * 60;
00099 #else
00100   ACE_NOTSUP_RETURN (0);
00101 #endif
00102 }
00103 
00104 
00105 #if !defined (ACE_LACKS_DIFFTIME)
00106 /// Helper for the ACE_OS::difftime() function
00107 /**
00108  * We moved the difftime code that used to be in ACE_OS::difftime()
00109  * here because on some platforms "difftime" is a macro.  Because of this,
00110  * the name ACE_OS::difftime will cause errors.  So in order to use the
00111  * macro as it is defined but also keep the name ACE_OS::difftime, we
00112  * use difftime first here in this inline function, and then undefine
00113  * it.
00114  */
00115 inline double ace_difftime(time_t t1, time_t t0)
00116 {
00117   return difftime (t1, t0);
00118 }
00119 #endif /* !ACE_LACKS_DIFFTIME */
00120 
00121 # if defined (ACE_WIN32)
00122 #   if !defined (ACE_LACKS_LONGLONG_T)
00123 // 64-bit quad-word definitions.
00124 typedef unsigned __int64 ACE_QWORD;
00125 typedef unsigned __int64 ACE_hrtime_t;
00126 inline ACE_QWORD ACE_MAKE_QWORD (DWORD lo, DWORD hi) { return ACE_QWORD (lo) | (ACE_QWORD (hi) << 32); }
00127 inline DWORD ACE_LOW_DWORD  (ACE_QWORD q) { return (DWORD) q; }
00128 inline DWORD ACE_HIGH_DWORD (ACE_QWORD q) { return (DWORD) (q >> 32); }
00129 #   else
00130 // Can't find ANY place that ACE_QWORD is used, but hrtime_t is.
00131 typedef ACE_UINT64 ACE_hrtime_t;
00132 #   endif // ACE_LACKS_LONGLONG_T
00133 # elif defined (_TNS_R_TARGET)
00134 typedef long long ACE_hrtime_t;
00135 # else /* !ACE_WIN32 */
00136 #   if defined (ACE_HAS_HI_RES_TIMER) &&  !defined (ACE_LACKS_LONGLONG_T)
00137   /* hrtime_t is defined on systems (Suns) with ACE_HAS_HI_RES_TIMER */
00138   typedef hrtime_t ACE_hrtime_t;
00139 #   else  /* ! ACE_HAS_HI_RES_TIMER  ||  ACE_LACKS_LONGLONG_T */
00140   typedef ACE_UINT64 ACE_hrtime_t;
00141 #   endif /* ! ACE_HAS_HI_RES_TIMER  ||  ACE_LACKS_LONGLONG_T */
00142 # endif /* ACE_WIN32 */
00143 
00144 # if defined (ACE_LACKS_UNSIGNEDLONGLONG_T)
00145 #   define ACE_HRTIME_CONVERSION(VAL) ACE_U64_TO_U32(VAL)
00146 #   define ACE_HRTIME_TO_U64(VAL) ACE_U_LongLong(VAL)
00147 # else
00148 #   define ACE_HRTIME_CONVERSION(VAL) (VAL)
00149 #   define ACE_HRTIME_TO_U64(VAL) (VAL)
00150 # endif
00151 
00152 namespace ACE_OS
00153 {
00154   enum ACE_HRTimer_Op
00155     {
00156       ACE_HRTIMER_START = 0x0,  // Only use these if you can stand
00157       ACE_HRTIMER_INCR = 0x1,   // for interrupts to be disabled during
00158       ACE_HRTIMER_STOP = 0x2,   // the timed interval!!!!
00159       ACE_HRTIMER_GETTIME = 0xFFFF
00160     };
00161 
00162   //@{ @name A set of wrappers for operations on time.
00163 
00164   ACE_NAMESPACE_INLINE_FUNCTION
00165   char *asctime (const struct tm *tm);
00166 
00167   ACE_NAMESPACE_INLINE_FUNCTION
00168   char *asctime_r (const struct tm *tm,
00169                    char *buf, int buflen);
00170 
00171   ACE_NAMESPACE_INLINE_FUNCTION
00172   int clock_gettime (clockid_t,
00173                      struct timespec *);
00174 
00175   ACE_NAMESPACE_INLINE_FUNCTION
00176   int clock_settime (clockid_t,
00177                      const struct timespec *);
00178 
00179   ACE_NAMESPACE_INLINE_FUNCTION
00180   ACE_TCHAR *ctime (const time_t *t);
00181 
00182 #if defined (ACE_HAS_WINCE) && !defined (_DEBUG)
00183   extern ACE_EXPORT_MACRO
00184 #else
00185   ACE_NAMESPACE_INLINE_FUNCTION
00186 #endif
00187   ACE_TCHAR *ctime_r (const time_t *clock, ACE_TCHAR *buf, int buflen);
00188 
00189 # if defined (difftime)
00190 #   undef difftime
00191 # endif /* difftime */
00192 
00193 #if !defined (ACE_LACKS_DIFFTIME)
00194   ACE_NAMESPACE_INLINE_FUNCTION
00195 #else
00196   extern ACE_Export
00197 #endif /* ! ACE_LACKS_DIFFTIME */
00198   double difftime (time_t t1,
00199                    time_t t0);
00200 
00201   ACE_NAMESPACE_INLINE_FUNCTION
00202   ACE_hrtime_t gethrtime (const ACE_HRTimer_Op = ACE_HRTIMER_GETTIME);
00203 
00204   ACE_NAMESPACE_INLINE_FUNCTION
00205   struct tm *gmtime (const time_t *clock);
00206 
00207   ACE_NAMESPACE_INLINE_FUNCTION
00208   struct tm *gmtime_r (const time_t *clock,
00209                        struct tm *res);
00210 
00211   ACE_NAMESPACE_INLINE_FUNCTION
00212   struct tm *localtime (const time_t *clock);
00213 
00214   extern ACE_Export
00215   struct tm *localtime_r (const time_t *clock,
00216                           struct tm *res);
00217 
00218   // Get the current time.
00219   extern ACE_Export
00220   time_t mktime (struct tm *timeptr);
00221 
00222   ACE_NAMESPACE_INLINE_FUNCTION
00223   int nanosleep (const struct timespec *requested,
00224                  struct timespec *remaining = 0);
00225 
00226 # if defined (ACE_HAS_POWERPC_TIMER) && defined (ghs)
00227   extern ACE_Export
00228   void readPPCTimeBase (u_long &most,
00229                         u_long &least);
00230 # endif /* ACE_HAS_POWERPC_TIMER && ghs */
00231 
00232   ACE_NAMESPACE_INLINE_FUNCTION
00233   size_t strftime (char *s,
00234                    size_t maxsize,
00235                    const char *format,
00236                    const struct tm *timeptr);
00237 
00238   ACE_NAMESPACE_INLINE_FUNCTION
00239   char *strptime (const char *buf,
00240                   const char *format,
00241                   struct tm *tm);
00242 
00243 # if defined (ACE_LACKS_STRPTIME) && !defined (ACE_REFUSE_STRPTIME_EMULATION)
00244   extern ACE_Export
00245   char *strptime_emulation (const char *buf,
00246                             const char *format,
00247                             struct tm *tm);
00248 
00249   extern ACE_Export
00250   int strptime_getnum (const char *buf, int *num, int *bi,
00251                        int *fi, int min, int max);
00252 # endif /* ACE_LACKS_STRPTIME && !ACE_REFUSE_STRPTIME_EMULATION */
00253 
00254   ACE_NAMESPACE_INLINE_FUNCTION
00255   time_t time (time_t *tloc = 0);
00256 
00257 # if defined (timezone)
00258 #   undef timezone
00259 # endif /* timezone */
00260 
00261   ACE_NAMESPACE_INLINE_FUNCTION
00262   long timezone (void);
00263 
00264   // wrapper for time zone information.
00265   ACE_NAMESPACE_INLINE_FUNCTION
00266   void tzset (void);
00267 
00268   //@}
00269 } /* namespace ACE_OS */
00270 
00271 ACE_END_VERSIONED_NAMESPACE_DECL
00272 
00273 #if (defined (ACE_HAS_VERSIONED_NAMESPACE) \
00274      && ACE_HAS_VERSIONED_NAMESPACE == 1) \
00275     && defined (ghs) \
00276     && defined (ACE_HAS_PENTIUM) \
00277     && !defined (ACE_WIN32)
00278 #define ACE_GETHRTIME_NAME ACE_PREPROC_CONCATENATE(ACE_,ACE_PREPROC_CONCATENATE(ACE_VERSIONED_NAMESPACE_NAME, _gethrtime))
00279 #else
00280 # define ACE_GETHRTIME_NAME ACE_gethrtime
00281 #endif  /* ACE_HAS_VERSIONED_NAMESPACE == 1 */
00282 
00283 
00284 # if defined (ACE_HAS_INLINED_OSCALLS)
00285 #   if defined (ACE_INLINE)
00286 #     undef ACE_INLINE
00287 #   endif /* ACE_INLINE */
00288 #   define ACE_INLINE inline
00289 #   include "ace/OS_NS_time.inl"
00290 # endif /* ACE_HAS_INLINED_OSCALLS */
00291 
00292 # include /**/ "ace/post.h"
00293 #endif /* ACE_OS_NS_TIME_H */

Generated on Sun Jan 27 12:05:34 2008 for ACE by doxygen 1.3.6