remove unneeded assert, move get_task_tls to sched_loop

This commit is contained in:
Jon Morton 2012-04-02 16:13:40 -05:00 committed by Brian Anderson
parent 33a949eed6
commit fa88d15d63
2 changed files with 27 additions and 27 deletions

View file

@ -38,6 +38,14 @@ private:
const int id;
static bool tls_initialized;
#ifndef __WIN32__
static pthread_key_t task_key;
#else
static DWORD task_key;
#endif
context c_context;
bool should_exit;
@ -62,13 +70,6 @@ private:
public:
rust_kernel *kernel;
rust_scheduler *sched;
static bool tls_initialized;
#ifndef __WIN32__
static pthread_key_t task_key;
#else
static DWORD task_key;
#endif
// NB: this is used to filter *runtime-originating* debug
// logging, on a per-scheduler basis. It's not likely what
@ -116,6 +117,8 @@ public:
void init_tls();
void place_task_in_tls(rust_task *task);
static rust_task *get_task_tls();
// Called by each task when they are ready to be destroyed
void release_task(rust_task *task);
@ -132,6 +135,21 @@ rust_sched_loop::get_log() {
return _log;
}
inline rust_task* rust_sched_loop::get_task_tls()
{
if (!tls_initialized)
return NULL;
#ifdef __WIN32__
rust_task *task = reinterpret_cast<rust_task *>
(TlsGetValue(task_key));
#else
rust_task *task = reinterpret_cast<rust_task *>
(pthread_getspecific(task_key));
#endif
assert(task && "Couldn't get the task from TLS!");
return task;
}
// NB: Runs on the Rust stack
inline stk_seg *
rust_sched_loop::borrow_c_stack() {

View file

@ -444,22 +444,6 @@ rust_task::record_stack_limit() {
record_sp_limit(stk->data + LIMIT_OFFSET + RED_ZONE_SIZE);
}
inline rust_task* __rust_get_task_tls()
{
if (!rust_sched_loop::tls_initialized)
return NULL;
#ifdef __WIN32__
rust_task *task = reinterpret_cast<rust_task *>
(TlsGetValue(rust_sched_loop::task_key));
#else
rust_task *task = reinterpret_cast<rust_task *>
(pthread_getspecific(rust_sched_loop::task_key));
#endif
assert(task && "Couldn't get the task from TLS!");
return task;
}
inline rust_task* rust_get_current_task() {
uintptr_t sp_limit = get_sp_limit();
@ -467,7 +451,7 @@ inline rust_task* rust_get_current_task() {
// 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_get_task_tls();
return rust_sched_loop::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
@ -476,11 +460,9 @@ inline rust_task* rust_get_current_task() {
uintptr_t seg_addr =
sp_limit - RED_ZONE_SIZE - LIMIT_OFFSET - sizeof(stk_seg);
stk_seg *stk = (stk_seg*) seg_addr;
// Make sure we've calculated the right address
::check_stack_canary(stk);
if (stk->task == NULL)
return __rust_get_task_tls();
return stk->task;
}