std: Reduce TLS access

This commit is contained in:
Brian Anderson 2013-08-16 20:14:30 -07:00
parent f9979247d1
commit 4c75d36d0e
2 changed files with 17 additions and 14 deletions

View File

@ -563,11 +563,10 @@ impl Scheduler {
// run the cleanup job, as expected by the previously called
// swap_contexts function.
unsafe {
let sched = Local::unsafe_borrow::<Scheduler>();
(*sched).run_cleanup_job();
let task = Local::unsafe_borrow::<Task>();
(*task).sched.get_mut_ref().run_cleanup_job();
// Must happen after running the cleanup job (of course).
let task = Local::unsafe_borrow::<Task>();
(*task).death.check_killed((*task).unwinder.unwinding);
}
}

View File

@ -281,20 +281,24 @@ impl<T> Drop for UnsafeAtomicRcBox<T>{
*/
// FIXME(#8140) should not be pub
pub unsafe fn atomically<U>(f: &fn() -> U) -> U {
use rt::task::Task;
use rt::task::{Task, GreenTask, SchedTask};
use rt::local::Local;
use rt::in_green_task_context;
if in_green_task_context() {
let t = Local::unsafe_borrow::<Task>();
do (|| {
(*t).death.inhibit_deschedule();
f()
}).finally {
(*t).death.allow_deschedule();
match Local::try_unsafe_borrow::<Task>() {
Some(t) => {
match (*t).task_type {
GreenTask(_) => {
do (|| {
(*t).death.inhibit_deschedule();
f()
}).finally {
(*t).death.allow_deschedule();
}
}
SchedTask => f()
}
}
} else {
f()
None => f()
}
}