aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGraydon Hoare <[email protected]>2010-07-22 15:05:35 -0700
committerGraydon Hoare <[email protected]>2010-07-22 15:05:35 -0700
commit0f220ecae921f961f0c40395218de86cc2b33849 (patch)
treee575036b7ab1d6b0031268aa854f52f55261d7c4
parentRe-introduce bits of vec-lib test that blocked on now-fixed issue #108. (diff)
downloadrust-0f220ecae921f961f0c40395218de86cc2b33849.tar.xz
rust-0f220ecae921f961f0c40395218de86cc2b33849.zip
Beat up on the preempt test a bit more, as it keeps hanging under valgrind.
-rw-r--r--src/rt/rust_internal.h11
-rw-r--r--src/rt/rust_timer.cpp5
-rw-r--r--src/rt/rust_upcall.cpp7
-rw-r--r--src/test/run-pass/preempt.rs2
4 files changed, 18 insertions, 7 deletions
diff --git a/src/rt/rust_internal.h b/src/rt/rust_internal.h
index d962e894..99f52165 100644
--- a/src/rt/rust_internal.h
+++ b/src/rt/rust_internal.h
@@ -67,6 +67,17 @@ struct frame_glue_fns;
static size_t const TIME_SLICE_IN_MS = 10;
+// This helps our preemption scheme handle "running on valgrind".
+
+#if defined(__WIN32__)
+#define YIELD_C_THREAD_IF_ON_VALGRIND (void);
+#else
+#define YIELD_C_THREAD_IF_ON_VALGRIND \
+ if (RUNNING_ON_VALGRIND) { \
+ pthread_yield(); \
+ }
+#endif
+
// Every reference counted object should derive from this base class.
template <typename T>
diff --git a/src/rt/rust_timer.cpp b/src/rt/rust_timer.cpp
index bf4d18e8..9427ec67 100644
--- a/src/rt/rust_timer.cpp
+++ b/src/rt/rust_timer.cpp
@@ -32,10 +32,9 @@ timer_loop(void *ptr) {
rust_dom *dom = timer->dom;
dom->log(rust_log::TIMER, "in timer 0x%" PRIxPTR, (uintptr_t)timer);
size_t ms = TIME_SLICE_IN_MS;
- if (!RUNNING_ON_VALGRIND)
- ms = 1;
while (!timer->exit_flag) {
+ YIELD_C_THREAD_IF_ON_VALGRIND;
#if defined(__WIN32__)
Sleep(ms);
#else
@@ -66,8 +65,6 @@ rust_timer::rust_timer(rust_dom *dom) :
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
pthread_create(&thread, &attr, timer_loop, (void *)this);
- if (RUNNING_ON_VALGRIND)
- usleep(10000);
#endif
}
diff --git a/src/rt/rust_upcall.cpp b/src/rt/rust_upcall.cpp
index 1aaf89fb..e931fc9b 100644
--- a/src/rt/rust_upcall.cpp
+++ b/src/rt/rust_upcall.cpp
@@ -1,21 +1,24 @@
#include "rust_internal.h"
+#include "valgrind.h"
// Upcalls.
#ifdef __GNUC__
#define LOG_UPCALL_ENTRY(task) \
+ YIELD_C_THREAD_IF_ON_VALGRIND; \
(task)->dom->get_log().reset_indent(0); \
(task)->log(rust_log::UPCALL, \
"> UPCALL %s - task: 0x%" PRIxPTR \
- " retpc: x%" PRIxPTR, \
+ " retpc: x%" PRIxPTR, \
__FUNCTION__, \
(task), __builtin_return_address(0)); \
(task)->dom->get_log().indent();
#else
#define LOG_UPCALL_ENTRY(task) \
+ YIELD_C_THREAD_IF_ON_VALGRIND; \
(task)->dom->get_log().reset_indent(0); \
(task)->log(rust_log::UPCALL, \
- "> UPCALL task: x%" PRIxPTR (task)); \
+ "> UPCALL task: x%" PRIxPTR (task)); \
(task)->dom->get_log().indent();
#endif
diff --git a/src/test/run-pass/preempt.rs b/src/test/run-pass/preempt.rs
index 00fc29ca..ee37bcf4 100644
--- a/src/test/run-pass/preempt.rs
+++ b/src/test/run-pass/preempt.rs
@@ -18,7 +18,7 @@ io fn main() {
log "main waiting for alive signal";
i <- alive;
log "main got alive signal";
- while (i < 1000) {
+ while (i < 50) {
log "main iterated";
i += 1;
}