From d39ea4774614f1db3366184f1e6ce30b7614d9ff Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 8 Feb 2012 17:46:12 -0800 Subject: [PATCH] rt: Remove rust_task_user struct --- src/rt/rust_builtin.cpp | 2 +- src/rt/rust_kernel.cpp | 8 ++++---- src/rt/rust_task.cpp | 22 ++++++++++------------ src/rt/rust_task.h | 18 ++++++------------ src/rt/rust_task_thread.cpp | 11 ++++------- 5 files changed, 25 insertions(+), 36 deletions(-) diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp index 9b02256041a..a3101e7edc9 100644 --- a/src/rt/rust_builtin.cpp +++ b/src/rt/rust_builtin.cpp @@ -439,7 +439,7 @@ rust_new_sched(uintptr_t threads) { extern "C" CDECL rust_task_id get_task_id() { rust_task *task = rust_task_thread::get_task(); - return task->user.id; + return task->id; } static rust_task_id diff --git a/src/rt/rust_kernel.cpp b/src/rt/rust_kernel.cpp index e210289cdb8..9768fffaf0b 100644 --- a/src/rt/rust_kernel.cpp +++ b/src/rt/rust_kernel.cpp @@ -161,12 +161,12 @@ rust_kernel::register_task(rust_task *task) { uintptr_t new_live_tasks; { scoped_lock with(task_lock); - task->user.id = max_task_id++; - task_table.put(task->user.id, task); + task->id = max_task_id++; + task_table.put(task->id, task); new_live_tasks = ++live_tasks; } - K(srv, task->user.id != INTPTR_MAX, "Hit the maximum task id"); - KLOG_("Registered task %" PRIdPTR, task->user.id); + K(srv, task->id != INTPTR_MAX, "Hit the maximum task id"); + KLOG_("Registered task %" PRIdPTR, task->id); KLOG_("Total outstanding tasks: %d", new_live_tasks); } diff --git a/src/rt/rust_task.cpp b/src/rt/rust_task.cpp index 398db5976bb..d2ebac63793 100644 --- a/src/rt/rust_task.cpp +++ b/src/rt/rust_task.cpp @@ -190,6 +190,8 @@ rust_task::rust_task(rust_task_thread *thread, rust_task_list *state, rust_task *spawner, const char *name, size_t init_stack_sz) : ref_count(1), + id(0), + notify_enabled(false), stk(NULL), runtime_sp(0), sched(thread->sched), @@ -216,12 +218,8 @@ rust_task::rust_task(rust_task_thread *thread, rust_task_list *state, LOGPTR(thread, "new task", (uintptr_t)this); DLOG(thread, task, "sizeof(task) = %d (0x%x)", sizeof *this, sizeof *this); - assert((void*)this == (void*)&user); - - user.notify_enabled = 0; - stk = new_stk(thread, this, init_stack_sz); - user.rust_sp = stk->end; + rust_sp = stk->end; if (supervisor) { supervisor->ref(); } @@ -338,7 +336,7 @@ rust_task::start(spawn_fn spawnee_fn, I(thread, stk->data != NULL); - char *sp = (char *)user.rust_sp; + char *sp = (char *)rust_sp; sp -= sizeof(spawn_args); @@ -614,14 +612,14 @@ rust_port *rust_task::get_port_by_id(rust_port_id id) { void rust_task::notify(bool success) { // FIXME (1078) Do this in rust code - if(user.notify_enabled) { - rust_task *target_task = kernel->get_task_by_id(user.notify_chan.task); + if(notify_enabled) { + rust_task *target_task = kernel->get_task_by_id(notify_chan.task); if (target_task) { rust_port *target_port = - target_task->get_port_by_id(user.notify_chan.port); + target_task->get_port_by_id(notify_chan.port); if(target_port) { task_notification msg; - msg.id = user.id; + msg.id = id; msg.result = !success ? tr_failure : tr_success; target_port->send(&msg); @@ -715,8 +713,8 @@ rust_task::check_stack_canary() { void rust_task::config_notify(chan_handle chan) { - user.notify_enabled = true; - user.notify_chan = chan; + notify_enabled = true; + notify_chan = chan; } // diff --git a/src/rt/rust_task.h b/src/rt/rust_task.h index bf3671409c3..61b6c982676 100644 --- a/src/rt/rust_task.h +++ b/src/rt/rust_task.h @@ -31,16 +31,6 @@ struct frame_glue_fns { uintptr_t reloc_glue_off; }; -// portions of the task structure that are accessible from the standard -// library. This struct must agree with the std::task::rust_task record. -struct rust_task_user { - rust_task_id id; - intptr_t notify_enabled; // this is way more bits than necessary, but it - // simplifies the alignment. - chan_handle notify_chan; - uintptr_t rust_sp; // Saved sp when not running. -}; - // std::lib::task::task_result typedef unsigned long task_result; #define tr_success 0 @@ -57,10 +47,14 @@ struct task_notification { struct rust_task : public kernel_owned, rust_cond { - rust_task_user user; - RUST_ATOMIC_REFCOUNT(); + rust_task_id id; + bool notify_enabled; + chan_handle notify_chan; + + uintptr_t rust_sp; // Saved sp when not running. + context ctx; stk_seg *stk; uintptr_t runtime_sp; // Runtime sp while task running. diff --git a/src/rt/rust_task_thread.cpp b/src/rt/rust_task_thread.cpp index 236eaaab98e..4830e1254d5 100644 --- a/src/rt/rust_task_thread.cpp +++ b/src/rt/rust_task_thread.cpp @@ -137,7 +137,7 @@ rust_task_thread::reap_dead_tasks() { for (size_t i = 0; i < dead_tasks_len; ++i) { rust_task *task = dead_tasks_copy[i]; // Release the task from the kernel so nobody else can get at it - kernel->release_task_id(task->user.id); + kernel->release_task_id(task->id); // Deref the task, which may cause it to request us to release it task->deref(); } @@ -151,7 +151,7 @@ rust_task_thread::release_task(rust_task *task) { // Nobody should have a ref to the task at this point I(this, task->ref_count == 0); // Kernel should not know about the task any more - I(this, kernel->get_task_by_id(task->user.id) == NULL); + I(this, kernel->get_task_by_id(task->id) == NULL); // Now delete the task, which will require using this thread's // memory region. delete task; @@ -249,11 +249,9 @@ rust_task_thread::start_main_loop() { DLOG(this, task, "activating task %s 0x%" PRIxPTR - ", sp=0x%" PRIxPTR ", state: %s", scheduled_task->name, (uintptr_t)scheduled_task, - scheduled_task->user.rust_sp, scheduled_task->state->name); place_task_in_tls(scheduled_task); @@ -265,11 +263,10 @@ rust_task_thread::start_main_loop() { DLOG(this, task, "returned from task %s @0x%" PRIxPTR - " in state '%s', sp=0x%x, worker id=%d" PRIxPTR, + " in state '%s', worker id=%d" PRIxPTR, scheduled_task->name, (uintptr_t)scheduled_task, scheduled_task->state->name, - scheduled_task->user.rust_sp, id); reap_dead_tasks(); @@ -305,7 +302,7 @@ rust_task_thread::create_task(rust_task *spawner, const char *name, } kernel->register_task(task); - return task->user.id; + return task->id; } void rust_task_thread::run() {