Skip to content

Commit 58e923d

Browse files
committed
rt: Perform task notification before killing the parent task
1 parent 138d9ca commit 58e923d

File tree

3 files changed

+27
-19
lines changed

3 files changed

+27
-19
lines changed

src/lib/comm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ resource port_ptr<uniq T>(po: *rustrt::rust_port) {
8181
while rustrt::rust_port_size(po) > 0u {
8282
// FIXME: For some reason if we don't assign to something here
8383
// we end up with invalid reads in the drop glue.
84-
let t = rusti::recv::<T>(po);
84+
let _t = rusti::recv::<T>(po);
8585
}
8686
rustrt::del_port(po);
8787
}

src/rt/rust_task.cpp

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -126,24 +126,6 @@ rust_task::~rust_task()
126126
DLOG(sched, task, "~rust_task %s @0x%" PRIxPTR ", refcnt=%d",
127127
name, (uintptr_t)this, ref_count);
128128

129-
if(user.notify_enabled) {
130-
rust_task *target_task = kernel->get_task_by_id(user.notify_chan.task);
131-
if (target_task) {
132-
rust_port *target_port =
133-
target_task->get_port_by_id(user.notify_chan.port);
134-
if(target_port) {
135-
task_notification msg;
136-
msg.id = user.id;
137-
msg.result = failed ? tr_failure : tr_success;
138-
139-
target_port->send(&msg);
140-
scoped_lock with(target_task->lock);
141-
target_port->deref();
142-
}
143-
target_task->deref();
144-
}
145-
}
146-
147129
if (supervisor) {
148130
supervisor->deref();
149131
}
@@ -203,6 +185,8 @@ void task_start_wrapper(spawn_args *a)
203185
failed = true;
204186
}
205187

188+
task->notify(!failed);
189+
206190
if (failed) {
207191
#ifndef __WIN32__
208192
task->conclude_failure();
@@ -605,6 +589,28 @@ rust_task::claim_alloc(void *alloc, const type_desc *tydesc) {
605589
lock.unlock();
606590
}
607591

592+
void
593+
rust_task::notify(bool success) {
594+
// FIXME (1078) Do this in rust code
595+
if(user.notify_enabled) {
596+
rust_task *target_task = kernel->get_task_by_id(user.notify_chan.task);
597+
if (target_task) {
598+
rust_port *target_port =
599+
target_task->get_port_by_id(user.notify_chan.port);
600+
if(target_port) {
601+
task_notification msg;
602+
msg.id = user.id;
603+
msg.result = !success ? tr_failure : tr_success;
604+
605+
target_port->send(&msg);
606+
scoped_lock with(target_task->lock);
607+
target_port->deref();
608+
}
609+
target_task->deref();
610+
}
611+
}
612+
}
613+
608614
//
609615
// Local Variables:
610616
// mode: C++

src/rt/rust_task.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@ rust_task : public kernel_owned<rust_task>, rust_cond
213213
// ground. We should never be migrating shared boxes between tasks.
214214
const type_desc *release_alloc(void *alloc);
215215
void claim_alloc(void *alloc, const type_desc *tydesc);
216+
217+
void notify(bool success);
216218
};
217219

218220
//

0 commit comments

Comments
 (0)