diff options
| author | Aaron Turon <aturon@mozilla.com> | 2014-11-24 16:38:06 -0800 |
|---|---|---|
| committer | Aaron Turon <aturon@mozilla.com> | 2014-12-18 23:31:34 -0800 |
| commit | b66681cd31674e1a2d0b9675ef8183c463470bb5 (patch) | |
| tree | 478c2accf952f3b9908428f57bc4557ce0f2b564 /src/libstd/rt | |
| parent | 74d07699938b846703ab552f52cd5c32f751900f (diff) | |
| download | rust-b66681cd31674e1a2d0b9675ef8183c463470bb5.tar.gz rust-b66681cd31674e1a2d0b9675ef8183c463470bb5.zip | |
Allow args to work without rt initialization
Diffstat (limited to 'src/libstd/rt')
| -rw-r--r-- | src/libstd/rt/args.rs | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/src/libstd/rt/args.rs b/src/libstd/rt/args.rs index 8b9dbf73c53..93c956fc3c5 100644 --- a/src/libstd/rt/args.rs +++ b/src/libstd/rt/args.rs @@ -62,37 +62,33 @@ mod imp { } pub unsafe fn cleanup() { - rtassert!(take().is_some()); + take(); LOCK.destroy(); } pub fn take() -> Option<Vec<Vec<u8>>> { - with_lock(|| unsafe { + let guard = LOCK.lock(); + unsafe { let ptr = get_global_ptr(); let val = mem::replace(&mut *ptr, None); val.as_ref().map(|s: &Box<Vec<Vec<u8>>>| (**s).clone()) - }) + } } pub fn put(args: Vec<Vec<u8>>) { - with_lock(|| unsafe { + let guard = LOCK.lock(); + unsafe { let ptr = get_global_ptr(); rtassert!((*ptr).is_none()); (*ptr) = Some(box args.clone()); - }) + } } pub fn clone() -> Option<Vec<Vec<u8>>> { - with_lock(|| unsafe { + let guard = LOCK.lock(); + unsafe { let ptr = get_global_ptr(); (*ptr).as_ref().map(|s: &Box<Vec<Vec<u8>>>| (**s).clone()) - }) - } - - fn with_lock<T, F>(f: F) -> T where F: FnOnce() -> T { - unsafe { - let _guard = LOCK.lock(); - f() } } |
