about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2013-05-08 15:26:07 -0700
committerBrian Anderson <banderson@mozilla.com>2013-05-15 12:19:14 -0700
commitf6401bad24d2fb1e1f959595c2f57cb4964e7082 (patch)
treeb8f1043af856875b64df032de0d82f39ba025c74 /src/libcore
parent36ad366519137122871b04b407370dab4a97c645 (diff)
core: Use a global lock instead of runtime lock for os::getenv, etc. #4726
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/os.rs26
1 files changed, 14 insertions, 12 deletions
diff --git a/src/libcore/os.rs b/src/libcore/os.rs
index 93319efa3b7..a198b495127 100644
--- a/src/libcore/os.rs
+++ b/src/libcore/os.rs
@@ -147,23 +147,25 @@ pub mod win32 {
 
 /*
 Accessing environment variables is not generally threadsafe.
-This uses a per-runtime lock to serialize access.
-FIXME #4726: It would probably be appropriate to make this a real global
+Serialize access through a global lock.
 */
 fn with_env_lock<T>(f: &fn() -> T) -> T {
-    use unstable::global::global_data_clone_create;
-    use unstable::sync::{Exclusive, exclusive};
-
-    struct SharedValue(());
-    type ValueMutex = Exclusive<SharedValue>;
-    fn key(_: ValueMutex) { }
+    use unstable::finally::Finally;
 
     unsafe {
-        let lock: ValueMutex = global_data_clone_create(key, || {
-            ~exclusive(SharedValue(()))
-        });
+        return do (|| {
+            rust_take_env_lock();
+            f()
+        }).finally {
+            rust_drop_env_lock();
+        };
+    }
 
-        lock.with_imm(|_| f() )
+    extern {
+        #[fast_ffi]
+        fn rust_take_env_lock();
+        #[fast_ffi]
+        fn rust_drop_env_lock();
     }
 }