From 44bef5f2cb175769155d92ec65bd6b16e6708a1e Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 8 Aug 2011 13:38:20 -0700 Subject: 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. --- src/rt/rust_kernel.cpp | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'src/rt/rust_kernel.cpp') 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() { -- cgit 1.4.1-3-g733a5