From a8c8bfc7b5525a83fab65f527345bb6ca46d4e25 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Fri, 11 Jan 2013 00:27:27 -0800 Subject: [PATCH] rt: Add rust_try_get_current_task --- src/rt/rust_sched_loop.h | 9 ++++++++- src/rt/rust_task.h | 10 ++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/rt/rust_sched_loop.h b/src/rt/rust_sched_loop.h index a5e6bc231e69..0105b83e28b4 100644 --- a/src/rt/rust_sched_loop.h +++ b/src/rt/rust_sched_loop.h @@ -135,6 +135,7 @@ public: void place_task_in_tls(rust_task *task); static rust_task *get_task_tls(); + static rust_task *try_get_task_tls(); // Called by each task when they are ready to be destroyed void release_task(rust_task *task); @@ -154,7 +155,7 @@ rust_sched_loop::get_log() { return _log; } -inline rust_task* rust_sched_loop::get_task_tls() +inline rust_task* rust_sched_loop::try_get_task_tls() { if (!tls_initialized) return NULL; @@ -165,6 +166,12 @@ inline rust_task* rust_sched_loop::get_task_tls() rust_task *task = reinterpret_cast (pthread_getspecific(task_key)); #endif + return task; +} + +inline rust_task* rust_sched_loop::get_task_tls() +{ + rust_task *task = try_get_task_tls(); assert(task && "Couldn't get the task from TLS!"); return task; } diff --git a/src/rt/rust_task.h b/src/rt/rust_task.h index bff4af09b32f..cbde863fa231 100644 --- a/src/rt/rust_task.h +++ b/src/rt/rust_task.h @@ -619,14 +619,14 @@ rust_task::record_stack_limit() { record_sp_limit(stk->data + LIMIT_OFFSET + RED_ZONE_SIZE); } -inline rust_task* rust_get_current_task() { +inline rust_task* rust_try_get_current_task() { uintptr_t sp_limit = get_sp_limit(); // FIXME (#1226) - Because of a hack in upcall_call_shim_on_c_stack this // value is sometimes inconveniently set to 0, so we can't use this // method of retreiving the task pointer and need to fall back to TLS. if (sp_limit == 0) - return rust_sched_loop::get_task_tls(); + return rust_sched_loop::try_get_task_tls(); // The stack pointer boundary is stored in a quickly-accessible location // in the TCB. From that we can calculate the address of the stack segment @@ -642,6 +642,12 @@ inline rust_task* rust_get_current_task() { return stk->task; } +inline rust_task* rust_get_current_task() { + rust_task* task = rust_try_get_current_task(); + assert(task != NULL && "no current task"); + return task; +} + // // Local Variables: // mode: C++