rt: Add rust_try_get_current_task

This commit is contained in:
Brian Anderson 2013-01-11 00:27:27 -08:00
parent 801f3225b2
commit a8c8bfc7b5
2 changed files with 16 additions and 3 deletions

View File

@ -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<rust_task *>
(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;
}

View File

@ -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++