mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-04-19 06:31:13 -03:00
Make assert_is_main_thread() simpler to optimize
The compiler cannot guarantee that a `static AtomicBool` is always the same initial value, but it can do so for a `const bool`.
This commit is contained in:
@@ -24,10 +24,7 @@ impl FloggableDebug for ThreadId {}
|
||||
/// The thread id of the main thread, as set by [`init()`] at startup.
|
||||
static mut MAIN_THREAD_ID: Option<ThreadId> = None;
|
||||
/// Used to bypass thread assertions when testing.
|
||||
#[cfg(not(test))]
|
||||
static THREAD_ASSERTS_CFG_FOR_TESTING: AtomicBool = AtomicBool::new(false);
|
||||
#[cfg(test)]
|
||||
static THREAD_ASSERTS_CFG_FOR_TESTING: AtomicBool = AtomicBool::new(true);
|
||||
const THREAD_ASSERTS_CFG_FOR_TESTING: bool = cfg!(test);
|
||||
/// This allows us to notice when we've forked.
|
||||
static IS_FORKED_PROC: AtomicBool = AtomicBool::new(false);
|
||||
|
||||
@@ -111,7 +108,7 @@ fn not_main_thread() -> ! {
|
||||
panic!("Function is not running on the main thread!");
|
||||
}
|
||||
|
||||
if !is_main_thread() && !THREAD_ASSERTS_CFG_FOR_TESTING.load(Ordering::Relaxed) {
|
||||
if !is_main_thread() && !THREAD_ASSERTS_CFG_FOR_TESTING {
|
||||
not_main_thread();
|
||||
}
|
||||
}
|
||||
@@ -123,7 +120,7 @@ fn not_background_thread() -> ! {
|
||||
panic!("Function is not allowed to be called on the main thread!");
|
||||
}
|
||||
|
||||
if is_main_thread() && !THREAD_ASSERTS_CFG_FOR_TESTING.load(Ordering::Relaxed) {
|
||||
if is_main_thread() && !THREAD_ASSERTS_CFG_FOR_TESTING {
|
||||
not_background_thread();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user