]> git.lizzy.rs Git - rust.git/commitdiff
Use AtomicBool instead of a 'static mut' for LLVM init posioning
authorRobin Kruppe <robin.kruppe@gmail.com>
Sun, 14 May 2017 18:33:37 +0000 (20:33 +0200)
committerRobin Kruppe <robin.kruppe@gmail.com>
Mon, 15 May 2017 09:13:33 +0000 (11:13 +0200)
src/librustc_trans/llvm_util.rs

index 0f4c6b6408015b49e5d185c3fb1bfe329aab7809..15f56036b0c1b933aebe49308108f51080d3f441 100644 (file)
 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");
         }
     }