diff options
| author | bors <bors@rust-lang.org> | 2013-12-31 20:41:56 -0800 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-12-31 20:41:56 -0800 |
| commit | e61937a6bf5e3a612dd8e2aa92061345f73d4b30 (patch) | |
| tree | 8bc04190803bd71c0d5e7730dfdb3318079d844b /src/libnative | |
| parent | 02cec05c550317f88cd8e3a4574f60ed731fe666 (diff) | |
| parent | c22fed9424a907beab53f6c6cd54afeff039f1b3 (diff) | |
| download | rust-e61937a6bf5e3a612dd8e2aa92061345f73d4b30.tar.gz rust-e61937a6bf5e3a612dd8e2aa92061345f73d4b30.zip | |
auto merge of #11187 : alexcrichton/rust/once, r=brson
Rationale can be found in the first commit, but this is basically the same thing as `pthread_once`
Diffstat (limited to 'src/libnative')
| -rw-r--r-- | src/libnative/io/net.rs | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/src/libnative/io/net.rs b/src/libnative/io/net.rs index 674f02d4a22..6736641c858 100644 --- a/src/libnative/io/net.rs +++ b/src/libnative/io/net.rs @@ -205,19 +205,14 @@ pub fn init() { } unsafe { - use std::unstable::mutex::{Mutex, MUTEX_INIT}; - static mut LOCK: Mutex = MUTEX_INIT; - static mut INITIALIZED: bool = false; - if INITIALIZED { return } - LOCK.lock(); - if !INITIALIZED { + use std::unstable::mutex::{Once, ONCE_INIT}; + static mut INIT: Once = ONCE_INIT; + INIT.doit(|| { let mut data: WSADATA = intrinsics::init(); let ret = WSAStartup(0x202, // version 2.2 &mut data); assert_eq!(ret, 0); - INITIALIZED = true; - } - LOCK.unlock(); + }); } } |
