Skip to content

Commit

Permalink
remove unneeded assert, move get_task_tls to sched_loop
Browse files Browse the repository at this point in the history
  • Loading branch information
jamorton authored and brson committed Apr 2, 2012
1 parent 33a949e commit fa88d15
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
32 changes: 25 additions & 7 deletions src/rt/rust_sched_loop.h
Expand Up @@ -38,6 +38,14 @@ struct rust_sched_loop

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;
Expand All @@ -62,13 +70,6 @@ struct rust_sched_loop
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
Expand Down Expand Up @@ -116,6 +117,8 @@ struct rust_sched_loop
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);

Expand All @@ -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() {
Expand Down
22 changes: 2 additions & 20 deletions src/rt/rust_task.h
Expand Up @@ -444,30 +444,14 @@ 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();

// 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_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
Expand All @@ -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;
}

Expand Down

0 comments on commit fa88d15

Please sign in to comment.