Skip to content

Commit

Permalink
Use Atomic
Browse files Browse the repository at this point in the history
  • Loading branch information
tyt2y3 committed Dec 8, 2023
1 parent fc04929 commit 046fea6
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/options.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use std::sync::atomic::{AtomicBool, Ordering};

static mut GLOBAL_OPTIONS: GlobalOptions = GlobalOptions {
prefer_more_parentheses: false,
prefer_more_parentheses: AtomicBool::new(false),
prefer_more_parentheses_set: false,
};

#[derive(Default)]
struct GlobalOptions {
prefer_more_parentheses: bool,
prefer_more_parentheses: AtomicBool,
prefer_more_parentheses_set: bool,
}

Expand All @@ -19,12 +21,16 @@ pub fn set_prefer_more_parentheses(v: bool) {
if GLOBAL_OPTIONS.prefer_more_parentheses_set {
panic!("Can't set the same global option `prefer_more_parentheses` twice");
}
GLOBAL_OPTIONS.prefer_more_parentheses = v;
*GLOBAL_OPTIONS.prefer_more_parentheses.get_mut() = v;
GLOBAL_OPTIONS.prefer_more_parentheses_set = true;
}
}

#[inline]
pub fn get_prefer_more_parentheses() -> bool {
unsafe { GLOBAL_OPTIONS.prefer_more_parentheses }
unsafe {
GLOBAL_OPTIONS
.prefer_more_parentheses
.load(Ordering::SeqCst)
}
}

0 comments on commit 046fea6

Please sign in to comment.