diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2013-07-10 22:14:40 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2013-07-11 00:21:26 -0700 |
| commit | e3fb7062aa2d7113c4ff4cb41a27bfb637465d57 (patch) | |
| tree | 815ebf09d654a97620713af95da1aad34f0830a3 /src/libstd/local_data.rs | |
| parent | cb5b9a477ccd2d04f549e1107af350749d414bba (diff) | |
| download | rust-e3fb7062aa2d7113c4ff4cb41a27bfb637465d57.tar.gz rust-e3fb7062aa2d7113c4ff4cb41a27bfb637465d57.zip | |
Work around stage0 to remove '@' requirements from TLS
Diffstat (limited to 'src/libstd/local_data.rs')
| -rw-r--r-- | src/libstd/local_data.rs | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/libstd/local_data.rs b/src/libstd/local_data.rs index d7ab7236b5c..a117d461cfd 100644 --- a/src/libstd/local_data.rs +++ b/src/libstd/local_data.rs @@ -66,6 +66,15 @@ pub type Key<'self,T> = &'self fn:Copy(v: T); * Remove a task-local data value from the table, returning the * reference that was originally created to insert it. */ +#[cfg(stage0)] +pub unsafe fn pop<T: 'static>(key: Key<@T>) -> Option<@T> { + local_pop(Handle::new(), key) +} +/** + * Remove a task-local data value from the table, returning the + * reference that was originally created to insert it. + */ +#[cfg(not(stage0))] pub unsafe fn pop<T: 'static>(key: Key<T>) -> Option<T> { local_pop(Handle::new(), key) } @@ -73,6 +82,15 @@ pub unsafe fn pop<T: 'static>(key: Key<T>) -> Option<T> { * Retrieve a task-local data value. It will also be kept alive in the * table until explicitly removed. */ +#[cfg(stage0)] +pub unsafe fn get<T: 'static>(key: Key<@T>) -> Option<@T> { + local_get(Handle::new(), key, |loc| loc.map(|&x| *x)) +} +/** + * Retrieve a task-local data value. It will also be kept alive in the + * table until explicitly removed. + */ +#[cfg(not(stage0))] pub unsafe fn get<T: 'static>(key: Key<@T>) -> Option<@T> { local_get(Handle::new(), key, |loc| loc.map(|&x| *x)) } @@ -80,13 +98,23 @@ pub unsafe fn get<T: 'static>(key: Key<@T>) -> Option<@T> { * Store a value in task-local data. If this key already has a value, * that value is overwritten (and its destructor is run). */ +#[cfg(stage0)] pub unsafe fn set<T: 'static>(key: Key<@T>, data: @T) { local_set(Handle::new(), key, data) } /** + * Store a value in task-local data. If this key already has a value, + * that value is overwritten (and its destructor is run). + */ +#[cfg(not(stage0))] +pub unsafe fn set<T: 'static>(key: Key<T>, data: T) { + local_set(Handle::new(), key, data) +} +/** * Modify a task-local data value. If the function returns 'None', the * data is removed (and its reference dropped). */ +#[cfg(stage0)] pub unsafe fn modify<T: 'static>(key: Key<@T>, f: &fn(Option<@T>) -> Option<@T>) { match f(pop(key)) { @@ -94,6 +122,18 @@ pub unsafe fn modify<T: 'static>(key: Key<@T>, None => {} } } +/** + * Modify a task-local data value. If the function returns 'None', the + * data is removed (and its reference dropped). + */ +#[cfg(not(stage0))] +pub unsafe fn modify<T: 'static>(key: Key<T>, + f: &fn(Option<T>) -> Option<T>) { + match f(pop(key)) { + Some(next) => { set(key, next); } + None => {} + } +} #[test] fn test_tls_multitask() { |
