about summary refs log tree commit diff
path: root/src/rt/sync
diff options
context:
space:
mode:
authorMichael Bebenita <mbebenita@mozilla.com>2010-09-10 01:21:29 -0700
committerMichael Bebenita <mbebenita@mozilla.com>2010-09-10 14:38:31 -0700
commita493350eb5ab38ba8a6563f3eb4a090d257b0d3a (patch)
treedc984eaa28a55de9f05db0b961a0e67f80ca35ef /src/rt/sync
parentf985fded3ede8a7677ca6c9c77817d27bc9ae492 (diff)
Cleanup, refactoring, and some runtime tests.
Diffstat (limited to 'src/rt/sync')
-rw-r--r--src/rt/sync/sync.cpp12
-rw-r--r--src/rt/sync/sync.h2
-rw-r--r--src/rt/sync/timer.cpp5
-rw-r--r--src/rt/sync/timer.h1
4 files changed, 20 insertions, 0 deletions
diff --git a/src/rt/sync/sync.cpp b/src/rt/sync/sync.cpp
index c754392aece..be874a115f0 100644
--- a/src/rt/sync/sync.cpp
+++ b/src/rt/sync/sync.cpp
@@ -11,6 +11,18 @@ void sync::yield() {
 #endif
 }
 
+void sync::sleep(size_t timeout_in_ms) {
+#ifdef __WIN32__
+    Sleep(timeout_in_ms);
+#else
+    usleep(timeout_in_ms * 1000);
+#endif
+}
+
+void sync::random_sleep(size_t max_timeout_in_ms) {
+    sleep(rand() % max_timeout_in_ms);
+}
+
 rust_thread::rust_thread() : _is_running(false), thread(0) {
     // Nop.
 }
diff --git a/src/rt/sync/sync.h b/src/rt/sync/sync.h
index 3829dafe650..bd755e1f9fe 100644
--- a/src/rt/sync/sync.h
+++ b/src/rt/sync/sync.h
@@ -4,6 +4,8 @@
 class sync {
 public:
     static void yield();
+    static void sleep(size_t timeout_in_ms);
+    static void random_sleep(size_t max_timeout_in_ms);
     template <class T>
     static bool compare_and_swap(T *address,
         T oldValue, T newValue) {
diff --git a/src/rt/sync/timer.cpp b/src/rt/sync/timer.cpp
index 0487b39796f..e6fe3688893 100644
--- a/src/rt/sync/timer.cpp
+++ b/src/rt/sync/timer.cpp
@@ -25,6 +25,11 @@ timer::get_elapsed_time() {
     return get_time() - _start;
 }
 
+double
+timer::get_elapsed_time_in_ms() {
+    return (double) get_elapsed_time() / 1000.0;
+}
+
 int64_t
 timer::get_timeout() {
     return _timeout - get_elapsed_time();
diff --git a/src/rt/sync/timer.h b/src/rt/sync/timer.h
index 509fd22cc0e..aae098a1119 100644
--- a/src/rt/sync/timer.h
+++ b/src/rt/sync/timer.h
@@ -17,6 +17,7 @@ public:
     timer();
     void reset(uint64_t timeout);
     uint64_t get_elapsed_time();
+    double get_elapsed_time_in_ms();
     int64_t get_timeout();
     bool has_timed_out();
     virtual ~timer();