Cleanup failure handling around rust_new_task_in_sched - closes #2668

This commit is contained in:
Ben Blum 2012-06-28 19:01:55 -04:00
parent d91e310982
commit 6fc730baf6
5 changed files with 9 additions and 3 deletions

View File

@ -538,6 +538,7 @@ fn spawn_raw(opts: task_opts, +f: fn~()) {
new_task_in_new_sched(sched_opts)
}
};
assert !new_task.is_null();
option::iter(opts.notify_chan) {|c|
// FIXME (#1087): Would like to do notification in Rust

View File

@ -95,6 +95,7 @@ rust_start(uintptr_t main_fn, int argc, char **argv, void* crate_map) {
// Create the main scheduler and the main task
rust_sched_id sched_id = kernel->create_scheduler(env->num_sched_threads);
rust_scheduler *sched = kernel->get_scheduler_by_id(sched_id);
assert(sched != NULL);
rust_task *root_task = sched->create_task(NULL, "main");
// Build the command line arguments to pass to the root task

View File

@ -630,7 +630,8 @@ extern "C" CDECL rust_task*
rust_new_task_in_sched(rust_sched_id id) {
rust_task *task = rust_get_current_task();
rust_scheduler *sched = task->kernel->get_scheduler_by_id(id);
// FIXME (#2668): What if we didn't get the scheduler?
if (sched == NULL)
return NULL;
return new_task_common(sched, task);
}

View File

@ -121,7 +121,9 @@ rust_kernel::get_scheduler_by_id(rust_sched_id id) {
rust_scheduler *
rust_kernel::get_scheduler_by_id_nolock(rust_sched_id id) {
assert(id != 0 && "invalid scheduler id");
if (id == 0) {
return NULL;
}
sched_lock.must_have_lock();
sched_map::iterator iter = sched_table.find(id);
if (iter != sched_table.end()) {

View File

@ -22,6 +22,7 @@ fn main() unsafe {
let new_sched_id = rustrt::rust_new_sched(num_threads);
#error("new_sched_id %?", new_sched_id);
let new_task_id = rustrt::rust_new_task_in_sched(new_sched_id);
assert !new_task_id.is_null();
let f = fn~() {
let child_sched_id = rustrt::rust_get_sched_id();
#error("child_sched_id %?", child_sched_id);
@ -33,4 +34,4 @@ fn main() unsafe {
rustrt::start_task(new_task_id, fptr);
unsafe::forget(f);
comm::recv(po);
}
}