Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit acdeedc

Browse files
author
Robin Kruppe
committedMay 15, 2017
Use AtomicBool instead of a 'static mut' for LLVM init posioning
1 parent e3f6e68 commit acdeedc

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed
 

‎src/librustc_trans/llvm_util.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,25 @@ use rustc::session::config::PrintRequest;
1616
use libc::{c_int, c_char};
1717
use std::ffi::CString;
1818

19+
use std::sync::atomic::{AtomicBool, Ordering};
20+
use std::sync::Once;
21+
1922
pub fn init(sess: &Session) {
2023
unsafe {
2124
// Before we touch LLVM, make sure that multithreading is enabled.
22-
use std::sync::Once;
25+
static POISONED: AtomicBool = AtomicBool::new(false);
2326
static INIT: Once = Once::new();
24-
static mut POISONED: bool = false;
2527
INIT.call_once(|| {
2628
if llvm::LLVMStartMultithreaded() != 1 {
2729
// use an extra bool to make sure that all future usage of LLVM
2830
// cannot proceed despite the Once not running more than once.
29-
POISONED = true;
31+
POISONED.store(true, Ordering::SeqCst);
3032
}
3133

3234
configure_llvm(sess);
3335
});
3436

35-
if POISONED {
37+
if POISONED.load(Ordering::SeqCst) {
3638
bug!("couldn't enable multi-threaded LLVM");
3739
}
3840
}

0 commit comments

Comments
 (0)
Please sign in to comment.