about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2013-08-22 22:29:04 -0700
committerBrian Anderson <banderson@mozilla.com>2013-08-23 18:38:56 -0700
commit0a1baef4f57b4ac8558a65b7bd8dc787ebf54840 (patch)
tree8c2542499373feefeda54e0afc72c126dbd677a5
parenta9d28b2d9d9939b1134d48feb1d83864bae782d5 (diff)
downloadrust-0a1baef4f57b4ac8558a65b7bd8dc787ebf54840.tar.gz
rust-0a1baef4f57b4ac8558a65b7bd8dc787ebf54840.zip
rt: Remove timer
-rw-r--r--mk/rt.mk1
-rw-r--r--src/rt/rust_builtin.cpp29
-rw-r--r--src/rt/rust_test_helpers.cpp1
-rw-r--r--src/rt/sync/timer.cpp85
-rw-r--r--src/rt/sync/timer.h37
5 files changed, 26 insertions, 127 deletions
diff --git a/mk/rt.mk b/mk/rt.mk
index 14bdbe6445c..e249c8cc657 100644
--- a/mk/rt.mk
+++ b/mk/rt.mk
@@ -63,7 +63,6 @@ endif
 endif
 
 RUNTIME_CXXS_$(1)_$(2) := \
-              rt/sync/timer.cpp \
               rt/sync/lock_and_signal.cpp \
               rt/sync/rust_thread.cpp \
               rt/rust_builtin.cpp \
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 {
diff --git a/src/rt/rust_test_helpers.cpp b/src/rt/rust_test_helpers.cpp
index b0aab9672ea..b9be4f1e251 100644
--- a/src/rt/rust_test_helpers.cpp
+++ b/src/rt/rust_test_helpers.cpp
@@ -11,7 +11,6 @@
 // Helper functions used only in tests
 
 #include "rust_util.h"
-#include "sync/timer.h"
 #include "sync/rust_thread.h"
 #include "sync/lock_and_signal.h"
 #include "rust_abi.h"
diff --git a/src/rt/sync/timer.cpp b/src/rt/sync/timer.cpp
deleted file mode 100644
index 99e5b107dc9..00000000000
--- a/src/rt/sync/timer.cpp
+++ /dev/null
@@ -1,85 +0,0 @@
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-#include "../rust_globals.h"
-#include "timer.h"
-
-#if defined(__APPLE__)
-#include <mach/mach_time.h>
-#endif
-
-uint64_t ns_per_s = 1000000000LL;
-
-timer::timer() {
-#if __WIN32__
-    _ticks_per_s = 0LL;
-    // FIXME (#2675): assert this works or have a workaround.
-    QueryPerformanceFrequency((LARGE_INTEGER *)&_ticks_per_s);
-    if (_ticks_per_s == 0LL) {
-      _ticks_per_s = 1LL;
-    }
-#endif
-    reset_us(0);
-}
-
-void
-timer::reset_us(uint64_t timeout_us) {
-    _start_us = time_us();
-    _timeout_us = timeout_us;
-}
-
-uint64_t
-timer::elapsed_us() {
-    return time_us() - _start_us;
-}
-
-double
-timer::elapsed_ms() {
-    return (double) elapsed_us() / 1000.0;
-}
-
-int64_t
-timer::remaining_us() {
-    return _timeout_us - elapsed_us();
-}
-
-bool
-timer::has_timed_out() {
-    return remaining_us() <= 0;
-}
-
-uint64_t
-timer::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);
-    return time_nano;
-#elif __WIN32__
-    uint64_t ticks;
-    QueryPerformanceCounter((LARGE_INTEGER *)&ticks);
-    return ((ticks * ns_per_s) / _ticks_per_s);
-#else
-    timespec ts;
-    clock_gettime(CLOCK_MONOTONIC, &ts);
-    return (ts.tv_sec * ns_per_s + ts.tv_nsec);
-#endif
-}
-
-uint64_t
-timer::time_us() {
-    return time_ns() / 1000;
-}
-
-timer::~timer() {
-}
diff --git a/src/rt/sync/timer.h b/src/rt/sync/timer.h
deleted file mode 100644
index 59d05878b50..00000000000
--- a/src/rt/sync/timer.h
+++ /dev/null
@@ -1,37 +0,0 @@
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-/*
- *  Utility class to measure time in a platform independent way.
- */
-
-#ifndef TIMER_H
-#define TIMER_H
-
-class timer {
-private:
-    uint64_t _start_us;
-    uint64_t _timeout_us;
-    uint64_t time_us();
-#if __WIN32__
-    uint64_t _ticks_per_s;
-#endif
-public:
-    timer();
-    void reset_us(uint64_t timeout);
-    uint64_t elapsed_us();
-    double elapsed_ms();
-    int64_t remaining_us();
-    bool has_timed_out();
-    uint64_t time_ns();
-    virtual ~timer();
-};
-
-#endif /* TIMER_H */