Cargo feature "multi_thread" for thread-local ATOM_TABLE_BUF_BASE
This commit is contained in:
@@ -13,6 +13,7 @@ build = "build/main.rs"
|
|||||||
rust-version = "1.63"
|
rust-version = "1.63"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
multi_thread = []
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
indexmap = "1.0.2"
|
indexmap = "1.0.2"
|
||||||
|
|||||||
@@ -40,17 +40,17 @@ impl From<bool> for Atom {
|
|||||||
const ATOM_TABLE_INIT_SIZE: usize = 1 << 16;
|
const ATOM_TABLE_INIT_SIZE: usize = 1 << 16;
|
||||||
const ATOM_TABLE_ALIGN: usize = 8;
|
const ATOM_TABLE_ALIGN: usize = 8;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(any(test, feature = "multi_thread"))]
|
||||||
thread_local! {
|
thread_local! {
|
||||||
static ATOM_TABLE_BUF_BASE: std::cell::RefCell<*const u8> = std::cell::RefCell::new(ptr::null_mut());
|
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> =
|
static ATOM_TABLE_BUF_BASE: std::sync::atomic::AtomicPtr<u8> =
|
||||||
std::sync::atomic::AtomicPtr::new(ptr::null_mut());
|
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> {
|
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| {
|
ATOM_TABLE_BUF_BASE.with(|atom_table_buf_base| {
|
||||||
let mut borrow = atom_table_buf_base.borrow_mut();
|
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
|
ATOM_TABLE_BUF_BASE
|
||||||
.compare_exchange(
|
.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 {
|
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())
|
ATOM_TABLE_BUF_BASE.with(|atom_table_buf_base| *atom_table_buf_base.borrow())
|
||||||
}
|
}
|
||||||
#[cfg(not(test))]
|
#[cfg(not(any(test, feature = "multi_thread")))]
|
||||||
{
|
{
|
||||||
ATOM_TABLE_BUF_BASE.load(std::sync::atomic::Ordering::Relaxed)
|
ATOM_TABLE_BUF_BASE.load(std::sync::atomic::Ordering::Relaxed)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user