diff options
| author | unknown <Eric@.(none)> | 2011-08-08 13:38:20 -0700 |
|---|---|---|
| committer | Eric Holk <eholk@mozilla.com> | 2011-08-08 16:55:38 -0700 |
| commit | 44bef5f2cb175769155d92ec65bd6b16e6708a1e (patch) | |
| tree | d7524b51e2af0cb191cd93cda3f282ac4ac8f4c6 /src/rt/rust_kernel.cpp | |
| parent | f4f057ced1f4152575571a6e5116e1ad5bb38beb (diff) | |
| download | rust-44bef5f2cb175769155d92ec65bd6b16e6708a1e.tar.gz rust-44bef5f2cb175769155d92ec65bd6b16e6708a1e.zip | |
Introduced task handles.
This is the new way to refer to tasks in rust-land. Currently all they do is serve as a key to look up the old rust_task structure. Ideally they won't be ref counted, but baby steps.
Diffstat (limited to 'src/rt/rust_kernel.cpp')
| -rw-r--r-- | src/rt/rust_kernel.cpp | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/src/rt/rust_kernel.cpp b/src/rt/rust_kernel.cpp index 24db485dd9d..4197f5dea89 100644 --- a/src/rt/rust_kernel.cpp +++ b/src/rt/rust_kernel.cpp @@ -9,6 +9,7 @@ rust_kernel::rust_kernel(rust_srv *srv, size_t num_threads) : _region(srv, true), _log(srv, NULL), srv(srv), + max_id(0), num_threads(num_threads), rval(0), live_tasks(0), @@ -133,10 +134,31 @@ int rust_kernel::start_task_threads() return rval; } -rust_task * +rust_task_id rust_kernel::create_task(rust_task *spawner, const char *name) { rust_scheduler *thread = threads[rand(&rctx) % num_threads]; - return thread->create_task(spawner, name); + rust_task *t = thread->create_task(spawner, name); + { + scoped_lock with(_kernel_lock); + t->id = max_id++; + task_table.put(t->id, t); + } + return t->id; +} + +rust_task * +rust_kernel::get_task_by_id(rust_task_id id) { + scoped_lock with(_kernel_lock); + rust_task *task = NULL; + // get leaves task unchanged if not found. + task_table.get(id, &task); + return task; +} + +void +rust_kernel::release_task_id(rust_task_id id) { + scoped_lock with(_kernel_lock); + task_table.remove(id); } void rust_kernel::wakeup_schedulers() { |
