diff options
| author | Erick Tryzelaar <erick.tryzelaar@gmail.com> | 2012-04-02 21:41:24 -0700 |
|---|---|---|
| committer | Erick Tryzelaar <erick.tryzelaar@gmail.com> | 2012-04-03 22:43:08 -0700 |
| commit | 4871f11439f8a867aed6f12e0c6cc86cd7dc518d (patch) | |
| tree | 1b292d291f81f4bf960d3ae0153338f90a6ed8bc /src/rt/rust_builtin.cpp | |
| parent | 7aae7320dbc0cb703417f38eb4d7aa7bd977e779 (diff) | |
| download | rust-4871f11439f8a867aed6f12e0c6cc86cd7dc518d.tar.gz rust-4871f11439f8a867aed6f12e0c6cc86cd7dc518d.zip | |
std: change timeval to ns resolution timespec
This lets us use the more precise clock_gettime on posix machines.
Diffstat (limited to 'src/rt/rust_builtin.cpp')
| -rw-r--r-- | src/rt/rust_builtin.cpp | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp index a5ef89bc201..a182d774e0d 100644 --- a/src/rt/rust_builtin.cpp +++ b/src/rt/rust_builtin.cpp @@ -408,7 +408,7 @@ rust_ptr_eq(type_desc *t, rust_box *a, rust_box *b) { #if defined(__WIN32__) extern "C" CDECL void -get_time(int64_t *sec, int32_t *usec) { +get_time(int64_t *sec, int32_t *nsec) { FILETIME fileTime; GetSystemTimeAsFileTime(&fileTime); @@ -423,15 +423,22 @@ get_time(int64_t *sec, int32_t *usec) { const uint64_t NANOSECONDS_FROM_1601_TO_1970 = 11644473600000000u; uint64_t ns_since_1970 = ns_since_1601 - NANOSECONDS_FROM_1601_TO_1970; *sec = ns_since_1970 / 1000000; - *usec = ns_since_1970 % 1000000; + *nsec = (ns_since_1970 % 1000000) * 1000; } #else extern "C" CDECL void -get_time(int64_t *sec, int32_t *usec) { +get_time(int64_t *sec, int32_t *nsec) { +#ifdef __APPLE__ struct timeval tv; gettimeofday(&tv, NULL); *sec = tv.tv_sec; - *usec = tv.tv_usec; + *nsec = tv.tv_usec * 1000; +#else + timespec ts; + clock_gettime(CLOCK_REALTIME, &ts); + *sec = ts.tv_sec; + *nsec = ts.tv_nsec; +#endif } #endif |
