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 80826 2008-03-04 14:51:23Z wotte $
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_LACKS_STRUCT_TM)
00051 struct tm {
00052   int tm_sec;
00053   int tm_min;
00054   int tm_hour;
00055   int tm_mday;      // Day of the month
00056   int tm_mon;
00057   int tm_year;
00058   int tm_wday;      // Day of the week
00059   int tm_yday;      // Day in the year
00060   int tm_isdst;     // >0 if dst in effet; 0 if not; <0 if unknown
00061 };
00062 #endif /* ACE_LACKS_STRUCT_TM */
00063 
00064 /// Helper for the ACE_OS::timezone() function
00065 /**
00066  * We put all the timezone stuff that used to be in ACE_OS::timezone()
00067  * here because on some platforms "timezone" is a macro.  Because of this,
00068  * the name ACE_OS::timezone will cause errors.  So in order to use the
00069  * macro as it is defined but also keep the name ACE_OS::timezone, we
00070  * use timezone first here in this inline function, and then undefine
00071  * timezone.
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   // The XPG/POSIX specification requires that tzset() be called to
00081   // set the global variable <timezone>.
00082   ::tzset();
00083   return timezone;
00084 #elif defined (ACE_HAS_TIMEZONE_GETTIMEOFDAY)
00085   // The XPG/POSIX specification does not require gettimeofday to
00086   // set the timezone struct (it leaves the behavior of passing a
00087   // non-null struct undefined).
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 /// Helper for the ACE_OS::difftime() function
00102 /**
00103  * We moved the difftime code that used to be in ACE_OS::difftime()
00104  * here because on some platforms "difftime" is a macro.  Because of this,
00105  * the name ACE_OS::difftime will cause errors.  So in order to use the
00106  * macro as it is defined but also keep the name ACE_OS::difftime, we
00107  * use difftime first here in this inline function, and then undefine
00108  * it.
00109  */
00110 inline double ace_difftime(time_t t1, time_t t0)
00111 {
00112   return difftime (t1, t0);
00113 }
00114 #endif /* !ACE_LACKS_DIFFTIME */
00115 
00116 # if defined (ACE_WIN32)
00117 #   if !defined (ACE_LACKS_LONGLONG_T)
00118 // 64-bit quad-word definitions.
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 // Can't find ANY place that ACE_QWORD is used, but hrtime_t is.
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 /* !ACE_WIN32 */
00131 #   if defined (ACE_HAS_HI_RES_TIMER) &&  !defined (ACE_LACKS_LONGLONG_T)
00132   /* hrtime_t is defined on systems (Suns) with ACE_HAS_HI_RES_TIMER */
00133   typedef hrtime_t ACE_hrtime_t;
00134 #   else  /* ! ACE_HAS_HI_RES_TIMER  ||  ACE_LACKS_LONGLONG_T */
00135   typedef ACE_UINT64 ACE_hrtime_t;
00136 #   endif /* ! ACE_HAS_HI_RES_TIMER  ||  ACE_LACKS_LONGLONG_T */
00137 # endif /* ACE_WIN32 */
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,  // Only use these if you can stand
00152       ACE_HRTIMER_INCR = 0x1,   // for interrupts to be disabled during
00153       ACE_HRTIMER_STOP = 0x2,   // the timed interval!!!!
00154       ACE_HRTIMER_GETTIME = 0xFFFF
00155     };
00156 
00157   //@{ @name A set of wrappers for operations on time.
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 /* difftime */
00187 
00188 #if !defined (ACE_LACKS_DIFFTIME)
00189   ACE_NAMESPACE_INLINE_FUNCTION
00190 #else
00191   extern ACE_Export
00192 #endif /* ! ACE_LACKS_DIFFTIME */
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   // Get the current time.
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 /* ACE_HAS_POWERPC_TIMER && ghs */
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 /* ACE_LACKS_STRPTIME && !ACE_REFUSE_STRPTIME_EMULATION */
00248 
00249   ACE_NAMESPACE_INLINE_FUNCTION
00250   time_t time (time_t *tloc = 0);
00251 
00252 # if defined (timezone)
00253 #   undef timezone
00254 # endif /* timezone */
00255 
00256   ACE_NAMESPACE_INLINE_FUNCTION
00257   long timezone (void);
00258 
00259   // wrapper for time zone information.
00260   ACE_NAMESPACE_INLINE_FUNCTION
00261   void tzset (void);
00262 
00263   //@}
00264 } /* namespace ACE_OS */
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  /* ACE_HAS_VERSIONED_NAMESPACE == 1 */
00277 
00278 
00279 # if defined (ACE_HAS_INLINED_OSCALLS)
00280 #   if defined (ACE_INLINE)
00281 #     undef ACE_INLINE
00282 #   endif /* ACE_INLINE */
00283 #   define ACE_INLINE inline
00284 #   include "ace/OS_NS_time.inl"
00285 # endif /* ACE_HAS_INLINED_OSCALLS */
00286 
00287 # include /**/ "ace/post.h"
00288 #endif /* ACE_OS_NS_TIME_H */

Generated on Tue Feb 2 17:18:41 2010 for ACE by  doxygen 1.4.7