Skip to content

Commit dc93e39

Browse files
committed
---
yaml --- r: 144362 b: refs/heads/try2 c: 5402786 h: refs/heads/master v: v3
1 parent ce3699a commit dc93e39

File tree

3 files changed

+32
-13
lines changed

3 files changed

+32
-13
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 468d023fe94aadbdc7b7dc0a83d264ee2ae0d68a
8+
refs/heads/try2: 5402786f94feac14adc337055eb0ca6c307b4f67
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libstd/rt/local.rs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ pub trait Local {
2626
}
2727

2828
impl Local for Task {
29+
#[inline]
2930
fn put(value: ~Task) { unsafe { local_ptr::put(value) } }
31+
#[inline]
3032
fn take() -> ~Task { unsafe { local_ptr::take() } }
3133
fn exists() -> bool { local_ptr::exists() }
3234
fn borrow<T>(f: &fn(&mut Task) -> T) -> T {
@@ -43,7 +45,9 @@ impl Local for Task {
4345
None => { rtabort!("function failed in local_borrow") }
4446
}
4547
}
48+
#[inline]
4649
unsafe fn unsafe_borrow() -> *mut Task { local_ptr::unsafe_borrow() }
50+
#[inline]
4751
unsafe fn try_unsafe_borrow() -> Option<*mut Task> {
4852
local_ptr::try_unsafe_borrow()
4953
}
@@ -57,12 +61,12 @@ impl Local for Scheduler {
5761
task.sched = Some(value.take());
5862
};
5963
}
64+
#[inline]
6065
fn take() -> ~Scheduler {
61-
do Local::borrow::<Task,~Scheduler> |task| {
62-
let sched = task.sched.take_unwrap();
63-
let task = task;
64-
task.sched = None;
65-
sched
66+
unsafe {
67+
// XXX: Unsafe for speed
68+
let task = Local::unsafe_borrow::<Task>();
69+
(*task).sched.take_unwrap()
6670
}
6771
}
6872
fn exists() -> bool {
@@ -97,10 +101,17 @@ impl Local for Scheduler {
97101
}
98102
}
99103
unsafe fn try_unsafe_borrow() -> Option<*mut Scheduler> {
100-
if Local::exists::<Scheduler>() {
101-
Some(Local::unsafe_borrow())
102-
} else {
103-
None
104+
match Local::try_unsafe_borrow::<Task>() {
105+
Some(task) => {
106+
match (*task).sched {
107+
Some(~ref mut sched) => {
108+
let s: *mut Scheduler = &mut *sched;
109+
Some(s)
110+
}
111+
None => None
112+
}
113+
}
114+
None => None
104115
}
105116
}
106117
}

branches/try2/src/libstd/rt/local_ptr.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ pub fn init_tls_key() {
4040
/// # Safety note
4141
///
4242
/// Does not validate the pointer type.
43+
#[inline]
4344
pub unsafe fn put<T>(sched: ~T) {
4445
let key = tls_key();
4546
let void_ptr: *mut c_void = cast::transmute(sched);
@@ -51,6 +52,7 @@ pub unsafe fn put<T>(sched: ~T) {
5152
/// # Safety note
5253
///
5354
/// Does not validate the pointer type.
55+
#[inline]
5456
pub unsafe fn take<T>() -> ~T {
5557
let key = tls_key();
5658
let void_ptr: *mut c_void = tls::get(key);
@@ -99,10 +101,15 @@ pub unsafe fn borrow<T>(f: &fn(&mut T)) {
99101
/// Because this leaves the value in thread-local storage it is possible
100102
/// For the Scheduler pointer to be aliased
101103
pub unsafe fn unsafe_borrow<T>() -> *mut T {
102-
match try_unsafe_borrow() {
103-
Some(p) => p,
104-
None => rtabort!("thread-local pointer is null. bogus!")
104+
let key = tls_key();
105+
let mut void_ptr: *mut c_void = tls::get(key);
106+
if void_ptr.is_null() {
107+
rtabort!("thread-local pointer is null. bogus!");
105108
}
109+
let ptr: *mut *mut c_void = &mut void_ptr;
110+
let ptr: *mut ~T = ptr as *mut ~T;
111+
let ptr: *mut T = &mut **ptr;
112+
return ptr;
106113
}
107114

108115
pub unsafe fn try_unsafe_borrow<T>() -> Option<*mut T> {
@@ -119,6 +126,7 @@ pub unsafe fn try_unsafe_borrow<T>() -> Option<*mut T> {
119126
}
120127
}
121128

129+
#[inline]
122130
fn tls_key() -> tls::Key {
123131
match maybe_tls_key() {
124132
Some(key) => key,

0 commit comments

Comments
 (0)