Skip to content

Commit 0f220ec

Browse files
committed
Beat up on the preempt test a bit more, as it keeps hanging under valgrind.
1 parent 3708865 commit 0f220ec

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

src/rt/rust_internal.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,17 @@ struct frame_glue_fns;
6767

6868
static size_t const TIME_SLICE_IN_MS = 10;
6969

70+
// This helps our preemption scheme handle "running on valgrind".
71+
72+
#if defined(__WIN32__)
73+
#define YIELD_C_THREAD_IF_ON_VALGRIND (void);
74+
#else
75+
#define YIELD_C_THREAD_IF_ON_VALGRIND \
76+
if (RUNNING_ON_VALGRIND) { \
77+
pthread_yield(); \
78+
}
79+
#endif
80+
7081
// Every reference counted object should derive from this base class.
7182

7283
template <typename T>

src/rt/rust_timer.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,9 @@ timer_loop(void *ptr) {
3232
rust_dom *dom = timer->dom;
3333
dom->log(rust_log::TIMER, "in timer 0x%" PRIxPTR, (uintptr_t)timer);
3434
size_t ms = TIME_SLICE_IN_MS;
35-
if (!RUNNING_ON_VALGRIND)
36-
ms = 1;
3735

3836
while (!timer->exit_flag) {
37+
YIELD_C_THREAD_IF_ON_VALGRIND;
3938
#if defined(__WIN32__)
4039
Sleep(ms);
4140
#else
@@ -66,8 +65,6 @@ rust_timer::rust_timer(rust_dom *dom) :
6665
pthread_attr_init(&attr);
6766
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
6867
pthread_create(&thread, &attr, timer_loop, (void *)this);
69-
if (RUNNING_ON_VALGRIND)
70-
usleep(10000);
7168
#endif
7269
}
7370

src/rt/rust_upcall.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
#include "rust_internal.h"
2+
#include "valgrind.h"
23

34
// Upcalls.
45

56
#ifdef __GNUC__
67
#define LOG_UPCALL_ENTRY(task) \
8+
YIELD_C_THREAD_IF_ON_VALGRIND; \
79
(task)->dom->get_log().reset_indent(0); \
810
(task)->log(rust_log::UPCALL, \
911
"> UPCALL %s - task: 0x%" PRIxPTR \
10-
" retpc: x%" PRIxPTR, \
12+
" retpc: x%" PRIxPTR, \
1113
__FUNCTION__, \
1214
(task), __builtin_return_address(0)); \
1315
(task)->dom->get_log().indent();
1416
#else
1517
#define LOG_UPCALL_ENTRY(task) \
18+
YIELD_C_THREAD_IF_ON_VALGRIND; \
1619
(task)->dom->get_log().reset_indent(0); \
1720
(task)->log(rust_log::UPCALL, \
18-
"> UPCALL task: x%" PRIxPTR (task)); \
21+
"> UPCALL task: x%" PRIxPTR (task)); \
1922
(task)->dom->get_log().indent();
2023
#endif
2124

src/test/run-pass/preempt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ io fn main() {
1818
log "main waiting for alive signal";
1919
i <- alive;
2020
log "main got alive signal";
21-
while (i < 1000) {
21+
while (i < 50) {
2222
log "main iterated";
2323
i += 1;
2424
}

0 commit comments

Comments
 (0)