diff options
| author | Huon Wilson <dbau.pp+github@gmail.com> | 2014-02-13 17:17:50 +1100 |
|---|---|---|
| committer | Huon Wilson <dbau.pp+github@gmail.com> | 2014-02-16 10:13:56 +1100 |
| commit | 76a59fd6e2d5c8c42193c047fd5eaba982d499f7 (patch) | |
| tree | a913c967de98b492f47fdd0bbd5a11cf0be96ed5 /src/libstd/rt | |
| parent | fba32ea79f1828ef441d91abca3635fad57f323d (diff) | |
| download | rust-76a59fd6e2d5c8c42193c047fd5eaba982d499f7.tar.gz rust-76a59fd6e2d5c8c42193c047fd5eaba982d499f7.zip | |
std: add an RAII unlocker to Mutex.
This automatically unlocks its lock when it goes out of scope, and provides a safe(ish) method to call .wait.
Diffstat (limited to 'src/libstd/rt')
| -rw-r--r-- | src/libstd/rt/args.rs | 15 |
1 files changed, 4 insertions, 11 deletions
diff --git a/src/libstd/rt/args.rs b/src/libstd/rt/args.rs index c417ea375fd..c91797c9559 100644 --- a/src/libstd/rt/args.rs +++ b/src/libstd/rt/args.rs @@ -68,7 +68,6 @@ mod imp { use option::{Option, Some, None}; use ptr::RawPtr; use iter::Iterator; - use unstable::finally::Finally; use unstable::mutex::{Mutex, MUTEX_INIT}; use mem; @@ -111,16 +110,10 @@ mod imp { } fn with_lock<T>(f: || -> T) -> T { - (|| { - unsafe { - lock.lock(); - f() - } - }).finally(|| { - unsafe { - lock.unlock(); - } - }) + unsafe { + let _guard = lock.lock(); + f() + } } fn get_global_ptr() -> *mut Option<~~[~[u8]]> { |
