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/libnative/io | |
| 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/libnative/io')
| -rw-r--r-- | src/libnative/io/net.rs | 3 | ||||
| -rw-r--r-- | src/libnative/io/timer_helper.rs | 3 |
2 files changed, 2 insertions, 4 deletions
diff --git a/src/libnative/io/net.rs b/src/libnative/io/net.rs index ec6a5c5cb9b..1de729aee2e 100644 --- a/src/libnative/io/net.rs +++ b/src/libnative/io/net.rs @@ -222,7 +222,7 @@ pub fn init() { static mut INITIALIZED: bool = false; static mut LOCK: Mutex = MUTEX_INIT; - LOCK.lock(); + let _guard = LOCK.lock(); if !INITIALIZED { let mut data: WSADATA = mem::init(); let ret = WSAStartup(0x202, // version 2.2 @@ -230,7 +230,6 @@ pub fn init() { assert_eq!(ret, 0); INITIALIZED = true; } - LOCK.unlock(); } } diff --git a/src/libnative/io/timer_helper.rs b/src/libnative/io/timer_helper.rs index 2c976e67d25..8ddce2c3990 100644 --- a/src/libnative/io/timer_helper.rs +++ b/src/libnative/io/timer_helper.rs @@ -41,7 +41,7 @@ pub fn boot(helper: fn(imp::signal, Port<Req>)) { static mut INITIALIZED: bool = false; unsafe { - LOCK.lock(); + let mut _guard = LOCK.lock(); if !INITIALIZED { let (msgp, msgc) = Chan::new(); // promote this to a shared channel @@ -58,7 +58,6 @@ pub fn boot(helper: fn(imp::signal, Port<Req>)) { rt::at_exit(proc() { shutdown() }); INITIALIZED = true; } - LOCK.unlock(); } } |
