Changeset 1204 in vbox for trunk/src/VBox/Runtime/r3
- Timestamp:
- Mar 5, 2007 12:01:10 AM (18 years ago)
- Location:
- trunk/src/VBox/Runtime/r3
- Files:
-
- 1 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r3/linux/time-linux.cpp
r1199 r1204 28 28 #include <sys/time.h> 29 29 #include <time.h> 30 #ifdef __LINUX__ 31 # include <sys/syscall.h> 32 # include <unistd.h> 33 # ifndef __NR_clock_gettime 34 # define __NR_timer_create 259 35 # define __NR_clock_gettime (__NR_timer_create+6) 36 # endif 37 #endif /* __LINUX__ */ 30 #include <sys/syscall.h> 31 #include <unistd.h> 32 #ifndef __NR_clock_gettime 33 # define __NR_timer_create 259 34 # define __NR_clock_gettime (__NR_timer_create+6) 35 #endif 38 36 39 37 #include <iprt/time.h> … … 41 39 42 40 43 #ifdef __LINUX__44 41 DECLINLINE(int) sys_clock_gettime(clockid_t id, struct timespec *ts) 45 42 { … … 49 46 return -1; 50 47 } 51 #endif /* __LINUX__ */52 48 53 49 … … 57 53 DECLINLINE(int) mono_clock(struct timespec *ts) 58 54 { 59 #if !defined(__OS2__) && !defined(__L4__)60 55 static int iWorking = -1; 61 56 switch (iWorking) … … 68 63 return clock_gettime(CLOCK_MONOTONIC, ts); 69 64 70 #ifdef __LINUX__71 65 /* 72 66 * Syscall clock_gettime(). … … 74 68 case 1: 75 69 return sys_clock_gettime(CLOCK_MONOTONIC, ts); 76 #endif /* __LINUX__ */77 70 78 71 #endif /* CLOCK_MONOTONIC */ … … 96 89 } 97 90 98 #ifdef __LINUX__99 91 rc = sys_clock_gettime(CLOCK_MONOTONIC, ts); 100 92 if (!rc) … … 103 95 return 0; 104 96 } 105 #endif /* __LINUX__ */106 97 #endif /* CLOCK_MONOTONIC */ 107 98 … … 111 102 } 112 103 } 113 #endif /* !__OS2__ && !__L4__ */114 104 return -1; 115 105 } … … 164 154 } 165 155 166 167 /**168 * Gets the current system time.169 *170 * @returns pTime.171 * @param pTime Where to store the time.172 */173 RTR3DECL(PRTTIMESPEC) RTTimeNow(PRTTIMESPEC pTime)174 {175 struct timeval tv;176 gettimeofday(&tv, NULL);177 return RTTimeSpecSetTimeval(pTime, &tv);178 }179 -
trunk/src/VBox/Runtime/r3/posix/RTTimeNow-posix.cpp
r1199 r1204 1 1 /* $Id$ */ 2 2 /** @file 3 * InnoTek Portable Runtime - Time, POSIX.3 * InnoTek Portable Runtime - RTTimeNow, POSIX. 4 4 */ 5 5 … … 28 28 #include <sys/time.h> 29 29 #include <time.h> 30 #ifdef __LINUX__31 # include <sys/syscall.h>32 # include <unistd.h>33 # ifndef __NR_clock_gettime34 # define __NR_timer_create 25935 # define __NR_clock_gettime (__NR_timer_create+6)36 # endif37 #endif /* __LINUX__ */38 30 39 31 #include <iprt/time.h> 40 #include "internal/time.h"41 42 43 #ifdef __LINUX__44 DECLINLINE(int) sys_clock_gettime(clockid_t id, struct timespec *ts)45 {46 int rc = syscall(__NR_clock_gettime, id, ts);47 if (rc >= 0)48 return rc;49 return -1;50 }51 #endif /* __LINUX__ */52 53 54 /**55 * Wrapper around various monotone time sources.56 */57 DECLINLINE(int) mono_clock(struct timespec *ts)58 {59 #if !defined(__OS2__) && !defined(__L4__)60 static int iWorking = -1;61 switch (iWorking)62 {63 #ifdef CLOCK_MONOTONIC64 /*65 * Standard clock_gettime()66 */67 case 0:68 return clock_gettime(CLOCK_MONOTONIC, ts);69 70 #ifdef __LINUX__71 /*72 * Syscall clock_gettime().73 */74 case 1:75 return sys_clock_gettime(CLOCK_MONOTONIC, ts);76 #endif /* __LINUX__ */77 78 #endif /* CLOCK_MONOTONIC */79 80 81 /*82 * Figure out what's working.83 */84 case -1:85 {86 int rc;87 #ifdef CLOCK_MONOTONIC88 /*89 * Real-Time API.90 */91 rc = clock_gettime(CLOCK_MONOTONIC, ts);92 if (!rc)93 {94 iWorking = 0;95 return 0;96 }97 98 #ifdef __LINUX__99 rc = sys_clock_gettime(CLOCK_MONOTONIC, ts);100 if (!rc)101 {102 iWorking = 1;103 return 0;104 }105 #endif /* __LINUX__ */106 #endif /* CLOCK_MONOTONIC */107 108 /* give up */109 iWorking = -2;110 break;111 }112 }113 #endif /* !__OS2__ && !__L4__ */114 return -1;115 }116 117 118 DECLINLINE(uint64_t) rtTimeGetSystemNanoTS(void)119 {120 /* check monotonic clock first. */121 static bool fMonoClock = true;122 if (fMonoClock)123 {124 struct timespec ts;125 if (!mono_clock(&ts))126 return (uint64_t)ts.tv_sec * (uint64_t)(1000 * 1000 * 1000)127 + ts.tv_nsec;128 fMonoClock = false;129 }130 131 /* fallback to gettimeofday(). */132 struct timeval tv;133 gettimeofday(&tv, NULL);134 return (uint64_t)tv.tv_sec * (uint64_t)(1000 * 1000 * 1000)135 + (uint64_t)(tv.tv_usec * 1000);136 }137 138 139 /**140 * Gets the current nanosecond timestamp.141 *142 * This differs from RTTimeNanoTS in that it will use system APIs and not do any143 * resolution or performance optimizations.144 *145 * @returns nanosecond timestamp.146 */147 RTDECL(uint64_t) RTTimeSystemNanoTS(void)148 {149 return rtTimeGetSystemNanoTS();150 }151 152 153 /**154 * Gets the current millisecond timestamp.155 *156 * This differs from RTTimeNanoTS in that it will use system APIs and not do any157 * resolution or performance optimizations.158 *159 * @returns millisecond timestamp.160 */161 RTDECL(uint64_t) RTTimeSystemMilliTS(void)162 {163 return rtTimeGetSystemNanoTS() / 1000000;164 }165 32 166 33 -
trunk/src/VBox/Runtime/r3/posix/time-posix.cpp
r1 r1204 28 28 #include <sys/time.h> 29 29 #include <time.h> 30 #ifdef __LINUX__31 # include <sys/syscall.h>32 # include <unistd.h>33 # ifndef __NR_clock_gettime34 # define __NR_timer_create 25935 # define __NR_clock_gettime (__NR_timer_create+6)36 # endif37 #endif /* __LINUX__ */38 30 39 31 #include <iprt/time.h> … … 41 33 42 34 43 #ifdef __LINUX__44 DECLINLINE(int) sys_clock_gettime(clockid_t id, struct timespec *ts)45 {46 int rc = syscall(__NR_clock_gettime, id, ts);47 if (rc >= 0)48 return rc;49 return -1;50 }51 #endif /* __LINUX__ */52 53 54 /**55 * Wrapper around various monotone time sources.56 */57 DECLINLINE(int) mono_clock(struct timespec *ts)58 {59 #if !defined(__OS2__) && !defined(__L4__)60 static int iWorking = -1;61 switch (iWorking)62 {63 #ifdef CLOCK_MONOTONIC64 /*65 * Standard clock_gettime()66 */67 case 0:68 return clock_gettime(CLOCK_MONOTONIC, ts);69 70 #ifdef __LINUX__71 /*72 * Syscall clock_gettime().73 */74 case 1:75 return sys_clock_gettime(CLOCK_MONOTONIC, ts);76 #endif /* __LINUX__ */77 78 #endif /* CLOCK_MONOTONIC */79 80 81 /*82 * Figure out what's working.83 */84 case -1:85 {86 int rc;87 #ifdef CLOCK_MONOTONIC88 /*89 * Real-Time API.90 */91 rc = clock_gettime(CLOCK_MONOTONIC, ts);92 if (!rc)93 {94 iWorking = 0;95 return 0;96 }97 98 #ifdef __LINUX__99 rc = sys_clock_gettime(CLOCK_MONOTONIC, ts);100 if (!rc)101 {102 iWorking = 1;103 return 0;104 }105 #endif /* __LINUX__ */106 #endif /* CLOCK_MONOTONIC */107 108 /* give up */109 iWorking = -2;110 break;111 }112 }113 #endif /* !__OS2__ && !__L4__ */114 return -1;115 }116 117 118 35 DECLINLINE(uint64_t) rtTimeGetSystemNanoTS(void) 119 36 { 37 #if defined(CLOCK_MONOTONIC) && !defined(__L4__) && !defined(__OS2__) 120 38 /* check monotonic clock first. */ 121 static bool fMonoClock = true;122 if ( fMonoClock)39 static bool s_fMonoClock = true; 40 if (s_fMonoClock) 123 41 { 124 42 struct timespec ts; 125 if (! mono_clock(&ts))43 if (!clock_gettime(CLOCK_MONOTONIC, &ts)) 126 44 return (uint64_t)ts.tv_sec * (uint64_t)(1000 * 1000 * 1000) 127 45 + ts.tv_nsec; 128 fMonoClock = false;46 s_fMonoClock = false; 129 47 } 48 #endif 130 49 131 50 /* fallback to gettimeofday(). */ … … 164 83 } 165 84 166 167 /**168 * Gets the current system time.169 *170 * @returns pTime.171 * @param pTime Where to store the time.172 */173 RTR3DECL(PRTTIMESPEC) RTTimeNow(PRTTIMESPEC pTime)174 {175 struct timeval tv;176 gettimeofday(&tv, NULL);177 return RTTimeSpecSetTimeval(pTime, &tv);178 }179
Note:
See TracChangeset
for help on using the changeset viewer.