Skip to content

Commit 7c8b3d8

Browse files
committed
---
yaml --- r: 144363 b: refs/heads/try2 c: 761f5fb h: refs/heads/master i: 144361: ce3699a 144359: 0e48cce v: v3
1 parent dc93e39 commit 7c8b3d8

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
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: 5402786f94feac14adc337055eb0ca6c307b4f67
8+
refs/heads/try2: 761f5fba69edb354cb3a02c01099f00c9bc56dc9
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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub trait Local {
2121
fn take() -> ~Self;
2222
fn exists() -> bool;
2323
fn borrow<T>(f: &fn(&mut Self) -> T) -> T;
24+
unsafe fn unsafe_take() -> ~Self;
2425
unsafe fn unsafe_borrow() -> *mut Self;
2526
unsafe fn try_unsafe_borrow() -> Option<*mut Self>;
2627
}
@@ -46,6 +47,8 @@ impl Local for Task {
4647
}
4748
}
4849
#[inline]
50+
unsafe fn unsafe_take() -> ~Task { local_ptr::unsafe_take() }
51+
#[inline]
4952
unsafe fn unsafe_borrow() -> *mut Task { local_ptr::unsafe_borrow() }
5053
#[inline]
5154
unsafe fn try_unsafe_borrow() -> Option<*mut Task> {
@@ -89,6 +92,7 @@ impl Local for Scheduler {
8992
}
9093
}
9194
}
95+
unsafe fn unsafe_take() -> ~Scheduler { rtabort!("unimpl") }
9296
unsafe fn unsafe_borrow() -> *mut Scheduler {
9397
match (*Local::unsafe_borrow::<Task>()).sched {
9498
Some(~ref mut sched) => {
@@ -122,6 +126,7 @@ impl Local for IoFactoryObject {
122126
fn take() -> ~IoFactoryObject { rtabort!("unimpl") }
123127
fn exists() -> bool { rtabort!("unimpl") }
124128
fn borrow<T>(_f: &fn(&mut IoFactoryObject) -> T) -> T { rtabort!("unimpl") }
129+
unsafe fn unsafe_take() -> ~IoFactoryObject { rtabort!("unimpl") }
125130
unsafe fn unsafe_borrow() -> *mut IoFactoryObject {
126131
let sched = Local::unsafe_borrow::<Scheduler>();
127132
let io: *mut IoFactoryObject = (*sched).event_loop.io().unwrap();

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,23 @@ pub unsafe fn take<T>() -> ~T {
6464
return ptr;
6565
}
6666

67+
/// Take ownership of a pointer from thread-local storage.
68+
///
69+
/// # Safety note
70+
///
71+
/// Does not validate the pointer type.
72+
/// Leaves the old pointer in TLS for speed.
73+
#[inline]
74+
pub unsafe fn unsafe_take<T>() -> ~T {
75+
let key = tls_key();
76+
let void_ptr: *mut c_void = tls::get(key);
77+
if void_ptr.is_null() {
78+
rtabort!("thread-local pointer is null. bogus!");
79+
}
80+
let ptr: ~T = cast::transmute(void_ptr);
81+
return ptr;
82+
}
83+
6784
/// Check whether there is a thread-local pointer installed.
6885
pub fn exists() -> bool {
6986
unsafe {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,9 @@ impl Scheduler {
505505
let mut this = self;
506506

507507
// The current task is grabbed from TLS, not taken as an input.
508-
let current_task: ~Task = Local::take::<Task>();
508+
// Doing an unsafe_take to avoid writing back a null pointer -
509+
// We're going to call `put` later to do that.
510+
let current_task: ~Task = unsafe { Local::unsafe_take::<Task>() };
509511

510512
// Check that the task is not in an atomically() section (e.g.,
511513
// holding a pthread mutex, which could deadlock the scheduler).

0 commit comments

Comments
 (0)