about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorRobin Kruppe <robin.kruppe@gmail.com>2017-05-14 20:33:37 +0200
committerRobin Kruppe <robin.kruppe@gmail.com>2017-05-15 11:13:33 +0200
commitacdeedc19253130798916a8bb20651657d9f01e5 (patch)
tree33ea9f258b14ac1e0e19ec8a7e8985ce025af722 /src
parente3f6e68d633040be0b88a0e11e6645bc506f8655 (diff)
downloadrust-acdeedc19253130798916a8bb20651657d9f01e5.tar.gz
rust-acdeedc19253130798916a8bb20651657d9f01e5.zip
Use AtomicBool instead of a 'static mut' for LLVM init posioning
Diffstat (limited to 'src')
-rw-r--r--src/librustc_trans/llvm_util.rs10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/librustc_trans/llvm_util.rs b/src/librustc_trans/llvm_util.rs
index 0f4c6b64080..15f56036b0c 100644
--- a/src/librustc_trans/llvm_util.rs
+++ b/src/librustc_trans/llvm_util.rs
@@ -16,23 +16,25 @@ use rustc::session::config::PrintRequest;
 use libc::{c_int, c_char};
 use std::ffi::CString;
 
+use std::sync::atomic::{AtomicBool, Ordering};
+use std::sync::Once;
+
 pub fn init(sess: &Session) {
     unsafe {
         // Before we touch LLVM, make sure that multithreading is enabled.
-        use std::sync::Once;
+        static POISONED: AtomicBool = AtomicBool::new(false);
         static INIT: Once = Once::new();
-        static mut POISONED: bool = false;
         INIT.call_once(|| {
             if llvm::LLVMStartMultithreaded() != 1 {
                 // use an extra bool to make sure that all future usage of LLVM
                 // cannot proceed despite the Once not running more than once.
-                POISONED = true;
+                POISONED.store(true, Ordering::SeqCst);
             }
 
             configure_llvm(sess);
         });
 
-        if POISONED {
+        if POISONED.load(Ordering::SeqCst) {
             bug!("couldn't enable multi-threaded LLVM");
         }
     }