Skip to content

Commit 04d9cc1

Browse files
committed
rt: Protect rust_task::supervisor with a lock
1 parent f4ce965 commit 04d9cc1

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/rt/rust_task.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ rust_task::rust_task(rust_task_thread *thread, rust_task_list *state,
7777
state(state),
7878
cond(NULL),
7979
cond_name("none"),
80-
supervisor(spawner),
8180
list_index(-1),
8281
next_port_id(0),
8382
rendezvous_ptr(0),
@@ -92,7 +91,8 @@ rust_task::rust_task(rust_task_thread *thread, rust_task_list *state,
9291
reentered_rust_stack(false),
9392
c_stack(NULL),
9493
next_c_sp(0),
95-
next_rust_sp(0)
94+
next_rust_sp(0),
95+
supervisor(spawner)
9696
{
9797
LOGPTR(thread, "new task", (uintptr_t)this);
9898
DLOG(thread, task, "sizeof(task) = %d (0x%x)", sizeof *this, sizeof *this);
@@ -103,6 +103,7 @@ rust_task::rust_task(rust_task_thread *thread, rust_task_list *state,
103103
}
104104
}
105105

106+
// NB: This does not always run on the task's scheduler thread
106107
void
107108
rust_task::delete_this()
108109
{
@@ -112,8 +113,11 @@ rust_task::delete_this()
112113
name, (uintptr_t)this, ref_count);
113114

114115
// FIXME: We should do this when the task exits, not in the destructor
115-
if (supervisor) {
116-
supervisor->deref();
116+
{
117+
scoped_lock with(supervisor_lock);
118+
if (supervisor) {
119+
supervisor->deref();
120+
}
117121
}
118122

119123
/* FIXME: tighten this up, there are some more
@@ -302,6 +306,7 @@ rust_task::conclude_failure() {
302306

303307
void
304308
rust_task::fail_parent() {
309+
scoped_lock with(supervisor_lock);
305310
if (supervisor) {
306311
DLOG(thread, task,
307312
"task %s @0x%" PRIxPTR
@@ -317,6 +322,7 @@ rust_task::fail_parent() {
317322
void
318323
rust_task::unsupervise()
319324
{
325+
scoped_lock with(supervisor_lock);
320326
if (supervisor) {
321327
DLOG(thread, task,
322328
"task %s @0x%" PRIxPTR

src/rt/rust_task.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ rust_task : public kernel_owned<rust_task>, rust_cond
7171
rust_task_list *state;
7272
rust_cond *cond;
7373
const char *cond_name;
74-
rust_task *supervisor; // Parent-link for failure propagation.
7574
int32_t list_index;
7675

7776
rust_port_id next_port_id;
@@ -120,6 +119,9 @@ rust_task : public kernel_owned<rust_task>, rust_cond
120119

121120
rust_port_selector port_selector;
122121

122+
lock_and_signal supervisor_lock;
123+
rust_task *supervisor; // Parent-link for failure propagation.
124+
123125
// Called when the atomic refcount reaches zero
124126
void delete_this();
125127

0 commit comments

Comments
 (0)