Skip to content

Commit fa88d15

Browse files
jamortonbrson
authored andcommitted
remove unneeded assert, move get_task_tls to sched_loop
1 parent 33a949e commit fa88d15

File tree

2 files changed

+27
-27
lines changed

2 files changed

+27
-27
lines changed

Diff for: src/rt/rust_sched_loop.h

+25-7
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ struct rust_sched_loop
3838

3939
const int id;
4040

41+
static bool tls_initialized;
42+
43+
#ifndef __WIN32__
44+
static pthread_key_t task_key;
45+
#else
46+
static DWORD task_key;
47+
#endif
48+
4149
context c_context;
4250

4351
bool should_exit;
@@ -62,13 +70,6 @@ struct rust_sched_loop
6270
public:
6371
rust_kernel *kernel;
6472
rust_scheduler *sched;
65-
static bool tls_initialized;
66-
67-
#ifndef __WIN32__
68-
static pthread_key_t task_key;
69-
#else
70-
static DWORD task_key;
71-
#endif
7273

7374
// NB: this is used to filter *runtime-originating* debug
7475
// logging, on a per-scheduler basis. It's not likely what
@@ -116,6 +117,8 @@ struct rust_sched_loop
116117
void init_tls();
117118
void place_task_in_tls(rust_task *task);
118119

120+
static rust_task *get_task_tls();
121+
119122
// Called by each task when they are ready to be destroyed
120123
void release_task(rust_task *task);
121124

@@ -132,6 +135,21 @@ rust_sched_loop::get_log() {
132135
return _log;
133136
}
134137

138+
inline rust_task* rust_sched_loop::get_task_tls()
139+
{
140+
if (!tls_initialized)
141+
return NULL;
142+
#ifdef __WIN32__
143+
rust_task *task = reinterpret_cast<rust_task *>
144+
(TlsGetValue(task_key));
145+
#else
146+
rust_task *task = reinterpret_cast<rust_task *>
147+
(pthread_getspecific(task_key));
148+
#endif
149+
assert(task && "Couldn't get the task from TLS!");
150+
return task;
151+
}
152+
135153
// NB: Runs on the Rust stack
136154
inline stk_seg *
137155
rust_sched_loop::borrow_c_stack() {

Diff for: src/rt/rust_task.h

+2-20
Original file line numberDiff line numberDiff line change
@@ -444,30 +444,14 @@ rust_task::record_stack_limit() {
444444
record_sp_limit(stk->data + LIMIT_OFFSET + RED_ZONE_SIZE);
445445
}
446446

447-
inline rust_task* __rust_get_task_tls()
448-
{
449-
if (!rust_sched_loop::tls_initialized)
450-
return NULL;
451-
#ifdef __WIN32__
452-
rust_task *task = reinterpret_cast<rust_task *>
453-
(TlsGetValue(rust_sched_loop::task_key));
454-
#else
455-
rust_task *task = reinterpret_cast<rust_task *>
456-
(pthread_getspecific(rust_sched_loop::task_key));
457-
#endif
458-
assert(task && "Couldn't get the task from TLS!");
459-
return task;
460-
461-
}
462-
463447
inline rust_task* rust_get_current_task() {
464448
uintptr_t sp_limit = get_sp_limit();
465449

466450
// FIXME (1226) - Because of a hack in upcall_call_shim_on_c_stack this
467451
// value is sometimes inconveniently set to 0, so we can't use this
468452
// method of retreiving the task pointer and need to fall back to TLS.
469453
if (sp_limit == 0)
470-
return __rust_get_task_tls();
454+
return rust_sched_loop::get_task_tls();
471455

472456
// The stack pointer boundary is stored in a quickly-accessible location
473457
// 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() {
476460
uintptr_t seg_addr =
477461
sp_limit - RED_ZONE_SIZE - LIMIT_OFFSET - sizeof(stk_seg);
478462
stk_seg *stk = (stk_seg*) seg_addr;
463+
479464
// Make sure we've calculated the right address
480465
::check_stack_canary(stk);
481-
482-
if (stk->task == NULL)
483-
return __rust_get_task_tls();
484466
return stk->task;
485467
}
486468

0 commit comments

Comments
 (0)