Changeset 3456 for pjproject/trunk/pjlib/src/pj/os_timestamp_posix.c
- Timestamp:
- Mar 16, 2011 9:22:24 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib/src/pj/os_timestamp_posix.c
r2394 r3456 25 25 #include <ctype.h> 26 26 27 #if defined(PJ_HAS_UNISTD_H) && PJ_HAS_UNISTD_H != 0 28 # include <unistd.h> 29 30 # if defined(_POSIX_TIMERS) && _POSIX_TIMERS > 0 && \ 31 defined(_POSIX_MONOTONIC_CLOCK) 32 # define USE_POSIX_TIMERS 1 33 # endif 34 35 #endif 36 27 37 #if defined(PJ_HAS_PENTIUM) && PJ_HAS_PENTIUM!=0 && \ 28 38 defined(PJ_TIMESTAMP_USE_RDTSC) && PJ_TIMESTAMP_USE_RDTSC!=0 && \ … … 111 121 } 112 122 123 #elif defined(PJ_DARWINOS) && PJ_DARWINOS != 0 124 #include <mach/mach.h> 125 #include <mach/clock.h> 126 #include <errno.h> 127 128 #define NSEC_PER_SEC 1000000000 129 130 PJ_DEF(pj_status_t) pj_get_timestamp(pj_timestamp *ts) 131 { 132 mach_timespec_t tp; 133 int ret; 134 clock_serv_t serv; 135 136 ret = host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &serv); 137 if (ret != KERN_SUCCESS) { 138 return PJ_RETURN_OS_ERROR(EINVAL); 139 } 140 141 ret = clock_get_time(serv, &tp); 142 if (ret != KERN_SUCCESS) { 143 return PJ_RETURN_OS_ERROR(EINVAL); 144 } 145 146 ts->u64 = tp.tv_sec; 147 ts->u64 *= NSEC_PER_SEC; 148 ts->u64 += tp.tv_nsec; 149 150 return PJ_SUCCESS; 151 } 152 153 PJ_DEF(pj_status_t) pj_get_timestamp_freq(pj_timestamp *freq) 154 { 155 freq->u32.hi = 0; 156 freq->u32.lo = NSEC_PER_SEC; 157 158 return PJ_SUCCESS; 159 } 160 161 #elif defined(USE_POSIX_TIMERS) && USE_POSIX_TIMERS != 0 162 #include <sys/time.h> 163 #include <errno.h> 164 165 #define NSEC_PER_SEC 1000000000 166 167 PJ_DEF(pj_status_t) pj_get_timestamp(pj_timestamp *ts) 168 { 169 struct timespec tp; 170 171 if (clock_gettime(CLOCK_MONOTONIC, &tp) != 0) { 172 return PJ_RETURN_OS_ERROR(pj_get_native_os_error()); 173 } 174 175 ts->u64 = tp.tv_sec; 176 ts->u64 *= NSEC_PER_SEC; 177 ts->u64 += tp.tv_nsec; 178 179 return PJ_SUCCESS; 180 } 181 182 PJ_DEF(pj_status_t) pj_get_timestamp_freq(pj_timestamp *freq) 183 { 184 freq->u32.hi = 0; 185 freq->u32.lo = NSEC_PER_SEC; 186 187 return PJ_SUCCESS; 188 } 189 113 190 #else 114 191 #include <sys/time.h> … … 141 218 142 219 #endif 143
Note: See TracChangeset
for help on using the changeset viewer.