diff options
| author | Brian Anderson <banderson@mozilla.com> | 2013-08-22 22:29:04 -0700 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2013-08-23 18:38:56 -0700 |
| commit | 0a1baef4f57b4ac8558a65b7bd8dc787ebf54840 (patch) | |
| tree | 8c2542499373feefeda54e0afc72c126dbd677a5 /src/rt/rust_builtin.cpp | |
| parent | a9d28b2d9d9939b1134d48feb1d83864bae782d5 (diff) | |
| download | rust-0a1baef4f57b4ac8558a65b7bd8dc787ebf54840.tar.gz rust-0a1baef4f57b4ac8558a65b7bd8dc787ebf54840.zip | |
rt: Remove timer
Diffstat (limited to 'src/rt/rust_builtin.cpp')
| -rw-r--r-- | src/rt/rust_builtin.cpp | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp index d7cb0296a17..cb81c149770 100644 --- a/src/rt/rust_builtin.cpp +++ b/src/rt/rust_builtin.cpp @@ -11,7 +11,6 @@ /* Foreign builtins. */ #include "rust_util.h" -#include "sync/timer.h" #include "sync/rust_thread.h" #include "sync/lock_and_signal.h" #include "memory_region.h" @@ -25,6 +24,7 @@ #ifdef __APPLE__ #include <crt_externs.h> +#include <mach/mach_time.h> #endif #if !defined(__WIN32__) @@ -242,10 +242,33 @@ get_time(int64_t *sec, int32_t *nsec) { } #endif +const uint64_t ns_per_s = 1000000000LL; + extern "C" CDECL void precise_time_ns(uint64_t *ns) { - timer t; - *ns = t.time_ns(); + +#ifdef __APPLE__ + uint64_t time = mach_absolute_time(); + mach_timebase_info_data_t info = {0, 0}; + if (info.denom == 0) { + mach_timebase_info(&info); + } + uint64_t time_nano = time * (info.numer / info.denom); + *ns = time_nano; +#elif __WIN32__ + uint64_t ticks_per_s; + QueryPerformanceFrequency((LARGE_INTEGER *)&ticks_per_s); + if (ticks_per_s == 0LL) { + ticks_per_s = 1LL; + } + uint64_t ticks; + QueryPerformanceCounter((LARGE_INTEGER *)&ticks); + *ns = ((ticks * ns_per_s) / ticks_per_s); +#else + timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + *ns = (ts.tv_sec * ns_per_s + ts.tv_nsec); +#endif } struct rust_tm { |
