Skip to content

Commit a8c8bfc

Browse files
committed
rt: Add rust_try_get_current_task
1 parent 801f322 commit a8c8bfc

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/rt/rust_sched_loop.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ struct rust_sched_loop
135135
void place_task_in_tls(rust_task *task);
136136

137137
static rust_task *get_task_tls();
138+
static rust_task *try_get_task_tls();
138139

139140
// Called by each task when they are ready to be destroyed
140141
void release_task(rust_task *task);
@@ -154,7 +155,7 @@ rust_sched_loop::get_log() {
154155
return _log;
155156
}
156157

157-
inline rust_task* rust_sched_loop::get_task_tls()
158+
inline rust_task* rust_sched_loop::try_get_task_tls()
158159
{
159160
if (!tls_initialized)
160161
return NULL;
@@ -165,6 +166,12 @@ inline rust_task* rust_sched_loop::get_task_tls()
165166
rust_task *task = reinterpret_cast<rust_task *>
166167
(pthread_getspecific(task_key));
167168
#endif
169+
return task;
170+
}
171+
172+
inline rust_task* rust_sched_loop::get_task_tls()
173+
{
174+
rust_task *task = try_get_task_tls();
168175
assert(task && "Couldn't get the task from TLS!");
169176
return task;
170177
}

src/rt/rust_task.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -619,14 +619,14 @@ rust_task::record_stack_limit() {
619619
record_sp_limit(stk->data + LIMIT_OFFSET + RED_ZONE_SIZE);
620620
}
621621

622-
inline rust_task* rust_get_current_task() {
622+
inline rust_task* rust_try_get_current_task() {
623623
uintptr_t sp_limit = get_sp_limit();
624624

625625
// FIXME (#1226) - Because of a hack in upcall_call_shim_on_c_stack this
626626
// value is sometimes inconveniently set to 0, so we can't use this
627627
// method of retreiving the task pointer and need to fall back to TLS.
628628
if (sp_limit == 0)
629-
return rust_sched_loop::get_task_tls();
629+
return rust_sched_loop::try_get_task_tls();
630630

631631
// The stack pointer boundary is stored in a quickly-accessible location
632632
// 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() {
642642
return stk->task;
643643
}
644644

645+
inline rust_task* rust_get_current_task() {
646+
rust_task* task = rust_try_get_current_task();
647+
assert(task != NULL && "no current task");
648+
return task;
649+
}
650+
645651
//
646652
// Local Variables:
647653
// mode: C++

0 commit comments

Comments
 (0)