diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2011-12-30 20:46:08 -0800 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2012-01-06 22:40:31 -0800 |
| commit | 98f5109cde838e66d629bf05c804ad1ca9b06c42 (patch) | |
| tree | 097edb4079a90bd4db126927e15494e686b25fd9 /src/rt/rust_task.cpp | |
| parent | e88905cd2882919f95084f41539ca9601ebf5cfc (diff) | |
| download | rust-98f5109cde838e66d629bf05c804ad1ca9b06c42.tar.gz rust-98f5109cde838e66d629bf05c804ad1ca9b06c42.zip | |
simplify task impl
Diffstat (limited to 'src/rt/rust_task.cpp')
| -rw-r--r-- | src/rt/rust_task.cpp | 48 |
1 files changed, 21 insertions, 27 deletions
diff --git a/src/rt/rust_task.cpp b/src/rt/rust_task.cpp index 2bf4c42a277..f63e8d8d4c0 100644 --- a/src/rt/rust_task.cpp +++ b/src/rt/rust_task.cpp @@ -292,14 +292,18 @@ rust_task::~rust_task() struct spawn_args { rust_task *task; - uintptr_t a3; - uintptr_t a4; - void (*CDECL f)(int *, uintptr_t, uintptr_t); + uintptr_t envptr; + spawn_fn f; }; -struct rust_closure_env { +struct rust_closure { + const type_desc *td; + // ... see trans_closure.rs for full description ... +}; + +struct rust_boxed_closure { intptr_t ref_count; - type_desc *td; + rust_closure closure; }; struct cleanup_args { @@ -315,13 +319,12 @@ cleanup_task(cleanup_args *args) { cc::do_cc(task); - rust_closure_env* env = (rust_closure_env*)a->a3; - if(env) { + rust_boxed_closure* boxed_env = (rust_boxed_closure*)a->envptr; + if(boxed_env) { // free the environment. - I(task->sched, 1 == env->ref_count); // the ref count better be 1 - //env->td->drop_glue(NULL, task, NULL, env->td->first_param, env); - //env->td->free_glue(NULL, task, NULL, env->td->first_param, env); - task->free(env); + rust_closure *env = &boxed_env->closure; + env->td->drop_glue(NULL, NULL, &env->td, env); + env->td->free_glue(NULL, NULL, &env->td, env); } task->die(); @@ -347,11 +350,12 @@ extern "C" CDECL void task_start_wrapper(spawn_args *a) { rust_task *task = a->task; - int rval = 42; bool failed = false; try { - a->f(&rval, a->a3, a->a4); + // The first argument is the return pointer; as the task fn + // must have void return type, we can safely pass 0. + a->f(0, a->envptr); } catch (rust_task *ex) { A(task->sched, ex == task, "Expected this task to be thrown for unwinding"); @@ -367,12 +371,11 @@ void task_start_wrapper(spawn_args *a) } void -rust_task::start(uintptr_t spawnee_fn, - uintptr_t args, +rust_task::start(spawn_fn spawnee_fn, uintptr_t env) { LOG(this, task, "starting task from fn 0x%" PRIxPTR - " with args 0x%" PRIxPTR, spawnee_fn, args); + " with env 0x%" PRIxPTR, spawnee_fn, env); I(sched, stk->data != NULL); @@ -383,23 +386,14 @@ rust_task::start(uintptr_t spawnee_fn, spawn_args *a = (spawn_args *)sp; a->task = this; - a->a3 = env; - a->a4 = args; - void **f = (void **)&a->f; - *f = (void *)spawnee_fn; + a->envptr = env; + a->f = spawnee_fn; ctx.call((void *)task_start_wrapper, a, sp); this->start(); } -void -rust_task::start(uintptr_t spawnee_fn, - uintptr_t args) -{ - start(spawnee_fn, args, 0); -} - void rust_task::start() { yield_timer.reset_us(0); |
