Skip to content

Commit 5ba7434

Browse files
committed
Avoid lifecycle_lock traffic in call_on_rust_stack. (close #3270)
1 parent e55c5ce commit 5ba7434

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

src/rt/rust_task.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,13 @@ MUST_CHECK bool rust_task::yield() {
248248

249249
// This check is largely superfluous; it's the one after the context swap
250250
// that really matters. This one allows us to assert a useful invariant.
251+
252+
// NB: This takes lifecycle_lock three times, and I believe that none of
253+
// them are actually necessary, as per #3213. Removing the locks here may
254+
// cause *harmless* races with a killer... but I didn't observe any
255+
// substantial performance improvement from removing them, even with
256+
// msgsend-ring-pipes, and also it's my last day, so I'm not about to
257+
// remove them. -- bblum
251258
if (must_fail_from_being_killed()) {
252259
{
253260
scoped_lock with(lifecycle_lock);

src/rt/rust_task.h

+6-10
Original file line numberDiff line numberDiff line change
@@ -431,12 +431,11 @@ rust_task::call_on_rust_stack(void *args, void *fn_ptr) {
431431
assert(get_sp_limit() != 0 && "Stack must be configured");
432432
assert(next_rust_sp);
433433

434-
bool had_reentered_rust_stack;
435-
{
436-
scoped_lock with(lifecycle_lock);
437-
had_reentered_rust_stack = reentered_rust_stack;
438-
reentered_rust_stack = true;
439-
}
434+
// Unlocked access. Might "race" a killer, but harmlessly. This code is
435+
// only run by the task itself, so cannot race itself. See the comment
436+
// above inhibit_kill (or #3213) in rust_task.cpp for justification.
437+
bool had_reentered_rust_stack = reentered_rust_stack;
438+
reentered_rust_stack = true;
440439

441440
uintptr_t prev_c_sp = next_c_sp;
442441
next_c_sp = get_sp();
@@ -448,10 +447,7 @@ rust_task::call_on_rust_stack(void *args, void *fn_ptr) {
448447
__morestack(args, fn_ptr, sp);
449448

450449
next_c_sp = prev_c_sp;
451-
{
452-
scoped_lock with(lifecycle_lock);
453-
reentered_rust_stack = had_reentered_rust_stack;
454-
}
450+
reentered_rust_stack = had_reentered_rust_stack;
455451

456452
record_sp_limit(0);
457453
}

0 commit comments

Comments
 (0)