2 #include "ace/os_include/sys/os_time.h"
3 #include "ace/os_include/os_errno.h"
5 #if defined (ACE_VXWORKS) || defined (ACE_HAS_CLOCK_GETTIME_REALTIME) || defined (ACE_LACKS_GETTIMEOFDAY)
6 # include "ace/OS_NS_time.h"
7 #endif /* ACE_VXWORKS || ACE_HAS_CLOCK_REALTIME */
9 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
11 ACE_INLINE ACE_Time_Value
12 ACE_OS::gettimeofday ()
14 // ACE_OS_TRACE ("ACE_OS::gettimeofday");
16 #if !defined (ACE_WIN32) && !defined (ACE_LACKS_GETTIMEOFDAY)
19 #endif // !defined (ACE_WIN32)
21 #if defined (ACE_LACKS_GETTIMEOFDAY) && defined (ACE_HAS_CLOCK_GETTIME)
23 if (ACE_OS::clock_gettime (CLOCK_REALTIME, &ts) == -1)
25 return ACE_Time_Value (-1);
28 return ACE_Time_Value (ts);
29 #elif defined (ACE_WIN32)
31 ::GetSystemTimeAsFileTime (&tfile);
32 return ACE_Time_Value (tfile);
34 # if defined (ACE_HAS_TIMEZONE_GETTIMEOFDAY) || \
35 defined (ACE_HAS_VOIDPTR_GETTIMEOFDAY) || \
36 defined (ACE_HAS_SVR4_GETTIMEOFDAY)
37 ACE_OSCALL (::gettimeofday (&tv, 0), int, result);
38 # elif defined (ACE_VXWORKS)
39 // Assumes that struct timespec is same size as struct timeval,
40 // which assumes that time_t is a long: it currently (VxWorks
44 ACE_OSCALL (ACE_OS::clock_gettime (CLOCK_REALTIME, &ts), int, result);
45 tv.tv_sec = ts.tv_sec;
46 tv.tv_usec = ts.tv_nsec / 1000L; // timespec has nsec, but timeval has usec
47 # elif defined (ACE_MQX)
50 tv.tv_sec = ts.SECONDS;
51 tv.tv_usec = ts.MILLISECONDS * 1000;
53 # if defined (ACE_LACKS_GETTIMEOFDAY)
54 ACE_NOTSUP_RETURN (ACE_Time_Value ((time_t)-1));
56 ACE_OSCALL (::gettimeofday (&tv), int, result);
57 # endif /* ACE_LACKS_GETTIMEOFDAY */
58 # endif /* ACE_HAS_SVR4_GETTIMEOFDAY */
60 #if !defined (ACE_WIN32) && !defined (ACE_LACKS_GETTIMEOFDAY)
62 return ACE_Time_Value ((time_t)-1);
64 return ACE_Time_Value (tv);
65 #endif // !defined (ACE_WIN32)
68 ACE_INLINE ACE_Time_Value
69 ACE_OS::gettimeofday_ ()
71 return ACE_OS::gettimeofday ();
74 ACE_END_VERSIONED_NAMESPACE_DECL