about summary refs log tree commit diff
path: root/src/libnative
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2014-01-16 19:57:59 -0800
committerAlex Crichton <alex@alexcrichton.com>2014-02-03 12:04:30 -0800
commit21e8466eca0536ab8ade7a74f7735fa6fda0142c (patch)
tree813493fe6358c5576adaca16d72fa2b78cf436c9 /src/libnative
parent99582f88847b6c1feba61c4cbce7e95308d5103b (diff)
downloadrust-21e8466eca0536ab8ade7a74f7735fa6fda0142c.tar.gz
rust-21e8466eca0536ab8ade7a74f7735fa6fda0142c.zip
extra: Re-add the Once primitve to extra::sync
This originally lived in std::unstable::mutex, but now it has a new home (and a
more proper one).
Diffstat (limited to 'src/libnative')
-rw-r--r--src/libnative/io/net.rs22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/libnative/io/net.rs b/src/libnative/io/net.rs
index ac68b1523d7..cf0b1f05ebd 100644
--- a/src/libnative/io/net.rs
+++ b/src/libnative/io/net.rs
@@ -201,14 +201,20 @@ pub fn init() {
     }
 
     unsafe {
-        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);
-        });
+        use std::unstable::mutex::{Mutex, MUTEX_INIT};
+        static mut INITIALIZED: bool = false;
+        static mut LOCK: Mutex = MUTEX_INIT;
+        unsafe {
+            LOCK.lock();
+            if !INITIALIZED {
+                let mut data: WSADATA = intrinsics::init();
+                let ret = WSAStartup(0x202,      // version 2.2
+                                     &mut data);
+                assert_eq!(ret, 0);
+                INITIALIZED = true;
+            }
+            LOCK.unlock();
+        }
     }
 }