about summary refs log tree commit diff
path: root/src/libnative/io
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-02-15 15:21:28 -0800
committerbors <bors@rust-lang.org>2014-02-15 15:21:28 -0800
commitd98668a55996d656072a4cac7abb1dcbbdf4f48b (patch)
tree9480a773995df199411254f148e321b64cd24556 /src/libnative/io
parent6b025c803c72d610c2ad4c950151b0d23782d114 (diff)
parent4668cdf3c4788e4a67f1b7dea0eb2d661ac05a49 (diff)
downloadrust-d98668a55996d656072a4cac7abb1dcbbdf4f48b.tar.gz
rust-d98668a55996d656072a4cac7abb1dcbbdf4f48b.zip
auto merge of #12235 : huonw/rust/raii-lock, r=alexcrichton
- adds a `LockGuard` type returned by `.lock` and `.trylock` that unlocks the mutex in the destructor
- renames `mutex::Mutex` to `StaticNativeMutex` 
- adds a `NativeMutex` type with a destructor
- removes `LittleLock`
- adds `#[must_use]` to `sync::mutex::Guard` to remind people to use it
Diffstat (limited to 'src/libnative/io')
-rw-r--r--src/libnative/io/net.rs7
-rw-r--r--src/libnative/io/timer_helper.rs7
2 files changed, 6 insertions, 8 deletions
diff --git a/src/libnative/io/net.rs b/src/libnative/io/net.rs
index ec6a5c5cb9b..b33b54862dc 100644
--- a/src/libnative/io/net.rs
+++ b/src/libnative/io/net.rs
@@ -218,11 +218,11 @@ pub fn init() {
     }
 
     unsafe {
-        use std::unstable::mutex::{Mutex, MUTEX_INIT};
+        use std::unstable::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
         static mut INITIALIZED: bool = false;
-        static mut LOCK: Mutex = MUTEX_INIT;
+        static mut LOCK: StaticNativeMutex = NATIVE_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..004cd6f3114 100644
--- a/src/libnative/io/timer_helper.rs
+++ b/src/libnative/io/timer_helper.rs
@@ -22,7 +22,7 @@
 
 use std::cast;
 use std::rt;
-use std::unstable::mutex::{Mutex, MUTEX_INIT};
+use std::unstable::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
 
 use bookkeeping;
 use io::timer::{Req, Shutdown};
@@ -37,11 +37,11 @@ static mut HELPER_CHAN: *mut Chan<Req> = 0 as *mut Chan<Req>;
 static mut HELPER_SIGNAL: imp::signal = 0 as imp::signal;
 
 pub fn boot(helper: fn(imp::signal, Port<Req>)) {
-    static mut LOCK: Mutex = MUTEX_INIT;
+    static mut LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT;
     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();
     }
 }