Skip to content

Commit 4c75d36

Browse files
committed
std: Reduce TLS access
1 parent f997924 commit 4c75d36

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

src/libstd/rt/sched.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -563,11 +563,10 @@ impl Scheduler {
563563
// run the cleanup job, as expected by the previously called
564564
// swap_contexts function.
565565
unsafe {
566-
let sched = Local::unsafe_borrow::<Scheduler>();
567-
(*sched).run_cleanup_job();
566+
let task = Local::unsafe_borrow::<Task>();
567+
(*task).sched.get_mut_ref().run_cleanup_job();
568568

569569
// Must happen after running the cleanup job (of course).
570-
let task = Local::unsafe_borrow::<Task>();
571570
(*task).death.check_killed((*task).unwinder.unwinding);
572571
}
573572
}

src/libstd/unstable/sync.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -281,20 +281,24 @@ impl<T> Drop for UnsafeAtomicRcBox<T>{
281281
*/
282282
// FIXME(#8140) should not be pub
283283
pub unsafe fn atomically<U>(f: &fn() -> U) -> U {
284-
use rt::task::Task;
284+
use rt::task::{Task, GreenTask, SchedTask};
285285
use rt::local::Local;
286-
use rt::in_green_task_context;
287-
288-
if in_green_task_context() {
289-
let t = Local::unsafe_borrow::<Task>();
290-
do (|| {
291-
(*t).death.inhibit_deschedule();
292-
f()
293-
}).finally {
294-
(*t).death.allow_deschedule();
286+
287+
match Local::try_unsafe_borrow::<Task>() {
288+
Some(t) => {
289+
match (*t).task_type {
290+
GreenTask(_) => {
291+
do (|| {
292+
(*t).death.inhibit_deschedule();
293+
f()
294+
}).finally {
295+
(*t).death.allow_deschedule();
296+
}
297+
}
298+
SchedTask => f()
299+
}
295300
}
296-
} else {
297-
f()
301+
None => f()
298302
}
299303
}
300304

0 commit comments

Comments
 (0)