]> Repositorios git - scryer-prolog.git/commitdiff
Cargo feature "multi_thread" for thread-local ATOM_TABLE_BUF_BASE
authorNicolas Luck <[email protected]>
Thu, 24 Aug 2023 17:12:09 +0000 (19:12 +0200)
committerNicolas Luck <[email protected]>
Thu, 24 Aug 2023 17:13:11 +0000 (19:13 +0200)
Cargo.toml
src/atom_table.rs

index 1ef29ebe7be58642eec779c12f02b071c4488c29..f594f3f4caab01484790eebf29ba068bccec7efa 100644 (file)
@@ -13,6 +13,7 @@ build = "build/main.rs"
 rust-version = "1.63"
 
 [features]
+multi_thread = []
 
 [build-dependencies]
 indexmap = "1.0.2"
index 48f50ec948a162b7fe2c4cfa70823c228490958b..bb7b56cfa3ad5cc250cf006cad715e6ff1eee399 100644 (file)
@@ -40,17 +40,17 @@ impl From<bool> 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<u8> =
     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)
     }