about summary refs log tree commit diff
path: root/src/rt
diff options
context:
space:
mode:
authorEric Holk <eholk@mozilla.com>2011-08-17 14:42:28 -0700
committerEric Holk <eholk@mozilla.com>2011-08-17 14:42:40 -0700
commitae89ea223de2fe5e9c9a5cdd2fa85a93828a7daa (patch)
tree1a28bb09eaeaf105bd84cc62c6a3e6c9ae2a8b8f /src/rt
parentefac7c9a197fa3ff3497ce99a2dda8693b3ef683 (diff)
downloadrust-ae89ea223de2fe5e9c9a5cdd2fa85a93828a7daa.tar.gz
rust-ae89ea223de2fe5e9c9a5cdd2fa85a93828a7daa.zip
Making more of the rust_task structure directly accessible from Rust.
Diffstat (limited to 'src/rt')
-rw-r--r--src/rt/arch/i386/context.cpp2
-rw-r--r--src/rt/rust_builtin.cpp20
-rw-r--r--src/rt/rust_kernel.cpp6
-rw-r--r--src/rt/rust_scheduler.cpp8
-rw-r--r--src/rt/rust_task.cpp13
-rw-r--r--src/rt/rust_task.h7
-rw-r--r--src/rt/rustrt.def.in1
7 files changed, 21 insertions, 36 deletions
diff --git a/src/rt/arch/i386/context.cpp b/src/rt/arch/i386/context.cpp
index a3853d636ee..f5fa3777eec 100644
--- a/src/rt/arch/i386/context.cpp
+++ b/src/rt/arch/i386/context.cpp
@@ -4,6 +4,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <assert.h>
 
 extern "C" uint32_t CDECL swap_registers(registers_t *oregs,
                                          registers_t *regs)
@@ -11,6 +12,7 @@ extern "C" uint32_t CDECL swap_registers(registers_t *oregs,
 
 context::context()
 {
+    assert((void*)&regs == (void*)this);
 }
 
 void context::swap(context &out)
diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp
index 2675368fd88..aa00de961b8 100644
--- a/src/rt/rust_builtin.cpp
+++ b/src/rt/rust_builtin.cpp
@@ -712,7 +712,7 @@ unpin_task(rust_task *task) {
 
 extern "C" CDECL rust_task_id
 get_task_id(rust_task *task) {
-    return task->id;
+    return task->user.id;
 }
 
 extern "C" CDECL rust_task_id
@@ -720,30 +720,16 @@ new_task(rust_task *task) {
     return task->kernel->create_task(task, NULL);
 }
 
-extern "C" CDECL registers_t *
-get_task_context(rust_task *task, rust_task_id id) {
-    rust_task *target = task->kernel->get_task_by_id(id);
-    registers_t *regs = &target->ctx.regs;
-    // This next line is a little dangerous.. It means we can only safely call
-    // this when starting a task.
-    regs->esp = target->rust_sp;
-    return regs;
-}
-
 extern "C" CDECL void
-drop_task(rust_task *task, rust_task_id tid) {
-    rust_task *target = task->kernel->get_task_by_id(tid);
+drop_task(rust_task *task, rust_task *target) {
     if(target) {
         target->deref();
-        // Deref twice because get_task_by_id does once.
-        target->deref();
     }
 }
 
 extern "C" CDECL rust_task *
 get_task_pointer(rust_task *task, rust_task_id id) {
-    rust_task *t = task->kernel->get_task_by_id(id);
-    return t;
+    return task->kernel->get_task_by_id(id);
 }
 
 extern "C" CDECL void
diff --git a/src/rt/rust_kernel.cpp b/src/rt/rust_kernel.cpp
index 02d15b31eb2..9899939da02 100644
--- a/src/rt/rust_kernel.cpp
+++ b/src/rt/rust_kernel.cpp
@@ -154,10 +154,10 @@ rust_kernel::create_task(rust_task *spawner, const char *name) {
     rust_task *t = thread->create_task(spawner, name);
     {
         scoped_lock with(_kernel_lock);
-        t->id = max_id++;
-        task_table.put(t->id, t);
+        t->user.id = max_id++;
+        task_table.put(t->user.id, t);
     }
-    return t->id;
+    return t->user.id;
 }
 
 rust_task *
diff --git a/src/rt/rust_scheduler.cpp b/src/rt/rust_scheduler.cpp
index 33e607a85e1..913f489c382 100644
--- a/src/rt/rust_scheduler.cpp
+++ b/src/rt/rust_scheduler.cpp
@@ -47,10 +47,10 @@ void
 rust_scheduler::activate(rust_task *task) {
     context ctx;
 
-    task->ctx.next = &ctx;
+    task->user.ctx.next = &ctx;
     DLOG(this, task, "descheduling...");
     lock.unlock();
-    task->ctx.swap(ctx);
+    task->user.ctx.swap(ctx);
     lock.lock();
     DLOG(this, task, "task has returned");
 }
@@ -226,7 +226,7 @@ rust_scheduler::start_main_loop() {
              ", state: %s",
              scheduled_task->name,
              (uintptr_t)scheduled_task,
-             scheduled_task->rust_sp,
+             scheduled_task->user.rust_sp,
              scheduled_task->state->name);
 
         interrupt_flag = 0;
@@ -244,7 +244,7 @@ rust_scheduler::start_main_loop() {
              scheduled_task->name,
              (uintptr_t)scheduled_task,
              scheduled_task->state->name,
-             scheduled_task->rust_sp,
+             scheduled_task->user.rust_sp,
              id);
 
         reap_dead_tasks(id);
diff --git a/src/rt/rust_task.cpp b/src/rt/rust_task.cpp
index b8269554237..7b8160f3637 100644
--- a/src/rt/rust_task.cpp
+++ b/src/rt/rust_task.cpp
@@ -57,7 +57,6 @@ rust_task::rust_task(rust_scheduler *sched, rust_task_list *state,
     ref_count(1),
     stk(NULL),
     runtime_sp(0),
-    rust_sp(0),
     gc_alloc_chain(0),
     sched(sched),
     cache(NULL),
@@ -86,7 +85,7 @@ rust_task::rust_task(rust_scheduler *sched, rust_task_list *state,
     user.notify_enabled = 0;
 
     stk = new_stk(sched, this, 0);
-    rust_sp = stk->limit;
+    user.rust_sp = stk->limit;
 }
 
 rust_task::~rust_task()
@@ -99,7 +98,7 @@ rust_task::~rust_task()
             get_chan_by_handle(&user.notify_chan);
         if(target) {
             task_notification msg;
-            msg.id = id;
+            msg.id = user.id;
             msg.result = failed ? tr_failure : tr_success;
 
             target->send(&msg);
@@ -107,7 +106,7 @@ rust_task::~rust_task()
         }
     }
 
-    kernel->release_task_id(id);
+    kernel->release_task_id(user.id);
 
     /* FIXME: tighten this up, there are some more
        assertions that hold at task-lifecycle events. */
@@ -166,7 +165,7 @@ rust_task::start(uintptr_t spawnee_fn,
 
     I(sched, stk->data != NULL);
 
-    char *sp = (char *)rust_sp;
+    char *sp = (char *)user.rust_sp;
 
     sp -= sizeof(spawn_args);
 
@@ -178,7 +177,7 @@ rust_task::start(uintptr_t spawnee_fn,
     void **f = (void **)&a->f;
     *f = (void *)spawnee_fn;
 
-    ctx.call((void *)task_start_wrapper, a, sp);
+    user.ctx.call((void *)task_start_wrapper, a, sp);
 
     this->start();
 }
@@ -213,7 +212,7 @@ rust_task::yield(size_t time_in_us) {
     yield_timer.reset_us(time_in_us);
 
     // Return to the scheduler.
-    ctx.next->swap(ctx);
+    user.ctx.next->swap(user.ctx);
 }
 
 void
diff --git a/src/rt/rust_task.h b/src/rt/rust_task.h
index f1513ada616..ea155687d98 100644
--- a/src/rt/rust_task.h
+++ b/src/rt/rust_task.h
@@ -38,8 +38,11 @@ struct gc_alloc {
 // 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;
     uint8_t notify_enabled;
     chan_handle notify_chan;
+    context ctx;
+    uintptr_t rust_sp;         // Saved sp when not running.
 };
 
 // std::lib::task::task_result
@@ -66,7 +69,6 @@ rust_task : public kernel_owned<rust_task>, rust_cond
     // Fields known to the compiler.
     stk_seg *stk;
     uintptr_t runtime_sp;      // Runtime sp while task running.
-    uintptr_t rust_sp;         // Saved sp when not running.
     gc_alloc *gc_alloc_chain;  // Linked list of GC allocations.
     rust_scheduler *sched;
     rust_crate_cache *cache;
@@ -82,7 +84,6 @@ rust_task : public kernel_owned<rust_task>, rust_cond
     size_t gc_alloc_thresh;
     size_t gc_alloc_accum;
 
-    rust_task_id id;
     rust_port_id next_port_id;
 
     // Keeps track of the last time this task yielded.
@@ -99,8 +100,6 @@ rust_task : public kernel_owned<rust_task>, rust_cond
     // List of tasks waiting for this task to finish.
     array_list<rust_task *> tasks_waiting_to_join;
 
-    context ctx;
-
     // This flag indicates that a worker is either currently running the task
     // or is about to run this task.
     int running_on;
diff --git a/src/rt/rustrt.def.in b/src/rt/rustrt.def.in
index f29c35acdda..ea3be315831 100644
--- a/src/rt/rustrt.def.in
+++ b/src/rt/rustrt.def.in
@@ -25,7 +25,6 @@ do_gc
 drop_port
 drop_task
 get_port_id
-get_task_context
 get_task_id
 get_task_pointer
 get_task_trampoline