From: Nicolas Luck Date: Thu, 24 Aug 2023 17:12:09 +0000 (+0200) Subject: Cargo feature "multi_thread" for thread-local ATOM_TABLE_BUF_BASE X-Git-Tag: remove^2~30 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=d13173942d35fb6261118a4e117b8f3dee964e3f;p=scryer-prolog.git Cargo feature "multi_thread" for thread-local ATOM_TABLE_BUF_BASE --- diff --git a/Cargo.toml b/Cargo.toml index 1ef29ebe..f594f3f4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,7 @@ build = "build/main.rs" rust-version = "1.63" [features] +multi_thread = [] [build-dependencies] indexmap = "1.0.2" diff --git a/src/atom_table.rs b/src/atom_table.rs index 48f50ec9..bb7b56cf 100644 --- a/src/atom_table.rs +++ b/src/atom_table.rs @@ -40,17 +40,17 @@ impl From for Atom { const ATOM_TABLE_INIT_SIZE: usize = 1 << 16; const ATOM_TABLE_ALIGN: usize = 8; -#[cfg(test)] +#[cfg(any(test, feature = "multi_thread"))] thread_local! { static ATOM_TABLE_BUF_BASE: std::cell::RefCell<*const u8> = std::cell::RefCell::new(ptr::null_mut()); } -#[cfg(not(test))] +#[cfg(all(not(test), not(feature = "multi_thread")))] static ATOM_TABLE_BUF_BASE: std::sync::atomic::AtomicPtr = std::sync::atomic::AtomicPtr::new(ptr::null_mut()); fn set_atom_tbl_buf_base(old_ptr: *const u8, new_ptr: *const u8) -> Result<(), *const u8> { -#[cfg(test)] + #[cfg(any(test, feature = "multi_thread"))] { ATOM_TABLE_BUF_BASE.with(|atom_table_buf_base| { let mut borrow = atom_table_buf_base.borrow_mut(); @@ -62,7 +62,7 @@ fn set_atom_tbl_buf_base(old_ptr: *const u8, new_ptr: *const u8) -> Result<(), * } })?; }; - #[cfg(not(test))] + #[cfg(all(not(test), not(feature = "multi_thread")))] { ATOM_TABLE_BUF_BASE .compare_exchange( @@ -77,11 +77,11 @@ fn set_atom_tbl_buf_base(old_ptr: *const u8, new_ptr: *const u8) -> Result<(), * } pub(crate) fn get_atom_tbl_buf_base() -> *const u8 { - #[cfg(test)] + #[cfg(any(test, feature = "multi_thread"))] { - ATOM_TABLE_BUF_BASE.with(|atom_table_buf_base| *atom_table_buf_base.borrow()) -} -#[cfg(not(test))] + ATOM_TABLE_BUF_BASE.with(|atom_table_buf_base| *atom_table_buf_base.borrow()) + } + #[cfg(not(any(test, feature = "multi_thread")))] { ATOM_TABLE_BUF_BASE.load(std::sync::atomic::Ordering::Relaxed) }