use std::sync::LazyLock;
use std::sync::atomic;
use std::sync::atomic::AtomicI64;
use std::sync::atomic::AtomicU32;
use std::sync::atomic::AtomicU64;
#[cfg(all(unix, feature = "sigbus-handler"))]
pub use crate::sigbus::register_sigbus_handler;
static UMASK: LazyLock<u32> = LazyLock::new(|| {
#[cfg(unix)]
unsafe {
let umask = libc::umask(0);
libc::umask(umask);
#[allow(clippy::useless_conversion)] return umask.into();
}
#[cfg(not(unix))]
{
return 0;
}
});
fn apply_masked_umask(mode: u32, mask: u32) -> u32 {
mode ^ (mask & *UMASK)
}
pub static SYMLINK_ATOMIC_WRITE: atomic::AtomicBool = atomic::AtomicBool::new(cfg!(test));
static ENFORCE_FSYNC: atomic::AtomicBool = atomic::AtomicBool::new(false);
pub static CHMOD_DIR: LazyLock<AtomicI64> =
LazyLock::new(|| AtomicI64::new(apply_masked_umask(0o2777, 0o7) as _));
pub static CHMOD_FILE: LazyLock<AtomicI64> =
LazyLock::new(|| AtomicI64::new(apply_masked_umask(0o666, 0o7) as _));
pub static INDEX_CHECKSUM_MAX_CHAIN_LEN: AtomicU32 = AtomicU32::new(10);
pub static INDEX_VERIFIED_CACHE: atomic::AtomicBool = atomic::AtomicBool::new(true);
pub static WEAK_BUFFER_GC_THRESHOLD: atomic::AtomicUsize = atomic::AtomicUsize::new(16);
static INDEX_LAG_FLUSH_TIMEOUT_SECS: AtomicU64 = AtomicU64::new(60);
static DETERMINISTIC_METADATA: atomic::AtomicBool = atomic::AtomicBool::new(false);
pub fn set_global_fsync(flag: bool) {
ENFORCE_FSYNC.store(flag, atomic::Ordering::Release);
}
pub fn get_global_fsync() -> bool {
ENFORCE_FSYNC.load(atomic::Ordering::Acquire)
}
pub fn set_page_out_threshold(threshold: i64) {
let old_threshold = crate::page_out::THRESHOLD.swap(threshold, atomic::Ordering::AcqRel);
let delta = threshold - old_threshold;
crate::page_out::adjust_available(delta);
}
pub fn set_index_lag_flush_timeout_secs(timeout_secs: u64) {
INDEX_LAG_FLUSH_TIMEOUT_SECS.store(timeout_secs, atomic::Ordering::Release);
}
pub fn get_index_lag_flush_timeout_secs() -> u64 {
INDEX_LAG_FLUSH_TIMEOUT_SECS.load(atomic::Ordering::Acquire)
}
pub fn set_deterministic_metadata(flag: bool) {
DETERMINISTIC_METADATA.store(flag, atomic::Ordering::Release);
}
pub(crate) fn get_deterministic_metadata() -> bool {
DETERMINISTIC_METADATA.load(atomic::Ordering::Acquire)
}