rt: Protect rust_task::supervisor with a lock
This commit is contained in:
parent
f4ce965ce7
commit
04d9cc18a5
2 changed files with 13 additions and 5 deletions
|
@ -77,7 +77,6 @@ rust_task::rust_task(rust_task_thread *thread, rust_task_list *state,
|
||||||
state(state),
|
state(state),
|
||||||
cond(NULL),
|
cond(NULL),
|
||||||
cond_name("none"),
|
cond_name("none"),
|
||||||
supervisor(spawner),
|
|
||||||
list_index(-1),
|
list_index(-1),
|
||||||
next_port_id(0),
|
next_port_id(0),
|
||||||
rendezvous_ptr(0),
|
rendezvous_ptr(0),
|
||||||
|
@ -92,7 +91,8 @@ rust_task::rust_task(rust_task_thread *thread, rust_task_list *state,
|
||||||
reentered_rust_stack(false),
|
reentered_rust_stack(false),
|
||||||
c_stack(NULL),
|
c_stack(NULL),
|
||||||
next_c_sp(0),
|
next_c_sp(0),
|
||||||
next_rust_sp(0)
|
next_rust_sp(0),
|
||||||
|
supervisor(spawner)
|
||||||
{
|
{
|
||||||
LOGPTR(thread, "new task", (uintptr_t)this);
|
LOGPTR(thread, "new task", (uintptr_t)this);
|
||||||
DLOG(thread, task, "sizeof(task) = %d (0x%x)", sizeof *this, sizeof *this);
|
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,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NB: This does not always run on the task's scheduler thread
|
||||||
void
|
void
|
||||||
rust_task::delete_this()
|
rust_task::delete_this()
|
||||||
{
|
{
|
||||||
|
@ -112,8 +113,11 @@ rust_task::delete_this()
|
||||||
name, (uintptr_t)this, ref_count);
|
name, (uintptr_t)this, ref_count);
|
||||||
|
|
||||||
// FIXME: We should do this when the task exits, not in the destructor
|
// FIXME: We should do this when the task exits, not in the destructor
|
||||||
if (supervisor) {
|
{
|
||||||
supervisor->deref();
|
scoped_lock with(supervisor_lock);
|
||||||
|
if (supervisor) {
|
||||||
|
supervisor->deref();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* FIXME: tighten this up, there are some more
|
/* FIXME: tighten this up, there are some more
|
||||||
|
@ -302,6 +306,7 @@ rust_task::conclude_failure() {
|
||||||
|
|
||||||
void
|
void
|
||||||
rust_task::fail_parent() {
|
rust_task::fail_parent() {
|
||||||
|
scoped_lock with(supervisor_lock);
|
||||||
if (supervisor) {
|
if (supervisor) {
|
||||||
DLOG(thread, task,
|
DLOG(thread, task,
|
||||||
"task %s @0x%" PRIxPTR
|
"task %s @0x%" PRIxPTR
|
||||||
|
@ -317,6 +322,7 @@ rust_task::fail_parent() {
|
||||||
void
|
void
|
||||||
rust_task::unsupervise()
|
rust_task::unsupervise()
|
||||||
{
|
{
|
||||||
|
scoped_lock with(supervisor_lock);
|
||||||
if (supervisor) {
|
if (supervisor) {
|
||||||
DLOG(thread, task,
|
DLOG(thread, task,
|
||||||
"task %s @0x%" PRIxPTR
|
"task %s @0x%" PRIxPTR
|
||||||
|
|
|
@ -71,7 +71,6 @@ rust_task : public kernel_owned<rust_task>, rust_cond
|
||||||
rust_task_list *state;
|
rust_task_list *state;
|
||||||
rust_cond *cond;
|
rust_cond *cond;
|
||||||
const char *cond_name;
|
const char *cond_name;
|
||||||
rust_task *supervisor; // Parent-link for failure propagation.
|
|
||||||
int32_t list_index;
|
int32_t list_index;
|
||||||
|
|
||||||
rust_port_id next_port_id;
|
rust_port_id next_port_id;
|
||||||
|
@ -120,6 +119,9 @@ private:
|
||||||
|
|
||||||
rust_port_selector port_selector;
|
rust_port_selector port_selector;
|
||||||
|
|
||||||
|
lock_and_signal supervisor_lock;
|
||||||
|
rust_task *supervisor; // Parent-link for failure propagation.
|
||||||
|
|
||||||
// Called when the atomic refcount reaches zero
|
// Called when the atomic refcount reaches zero
|
||||||
void delete_this();
|
void delete_this();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue