nightly feature gate
This commit is contained in:
parent
42443518e1
commit
71f1767092
|
@ -7,5 +7,6 @@ edition = "2024"
|
||||||
default = ["alloc"]
|
default = ["alloc"]
|
||||||
alloc = []
|
alloc = []
|
||||||
std = []
|
std = []
|
||||||
|
nightly = []
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
|
@ -35,7 +35,7 @@ use core::ops::{Deref, DerefMut};
|
||||||
/// Alignment and padding:
|
/// Alignment and padding:
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// use crossbeam_utils::CachePadded;
|
/// use werkzeug::CachePadded;
|
||||||
///
|
///
|
||||||
/// let array = [CachePadded::new(1i8), CachePadded::new(2i8)];
|
/// let array = [CachePadded::new(1i8), CachePadded::new(2i8)];
|
||||||
/// let addr1 = &*array[0] as *const i8 as usize;
|
/// let addr1 = &*array[0] as *const i8 as usize;
|
||||||
|
@ -51,7 +51,7 @@ use core::ops::{Deref, DerefMut};
|
||||||
/// each other's cache lines:
|
/// each other's cache lines:
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// use crossbeam_utils::CachePadded;
|
/// use werkzeug::CachePadded;
|
||||||
/// use std::sync::atomic::AtomicUsize;
|
/// use std::sync::atomic::AtomicUsize;
|
||||||
///
|
///
|
||||||
/// struct Queue<T> {
|
/// struct Queue<T> {
|
||||||
|
@ -159,7 +159,7 @@ impl<T> CachePadded<T> {
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// use crossbeam_utils::CachePadded;
|
/// use werkzeug::CachePadded;
|
||||||
///
|
///
|
||||||
/// let padded_value = CachePadded::new(1);
|
/// let padded_value = CachePadded::new(1);
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -172,7 +172,7 @@ impl<T> CachePadded<T> {
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// use crossbeam_utils::CachePadded;
|
/// use werkzeug::CachePadded;
|
||||||
///
|
///
|
||||||
/// let padded_value = CachePadded::new(7);
|
/// let padded_value = CachePadded::new(7);
|
||||||
/// let value = padded_value.into_inner();
|
/// let value = padded_value.into_inner();
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#![cfg_attr(not(feature = "std"), no_std)]
|
#![cfg_attr(not(feature = "std"), no_std)]
|
||||||
|
#![cfg_attr(feature = "nightly", feature(strict_provenance_atomic_ptr))]
|
||||||
|
|
||||||
#[cfg(any(test, feature = "std", feature = "alloc"))]
|
#[cfg(any(test, feature = "std", feature = "alloc"))]
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
|
@ -14,4 +15,5 @@ pub mod rand;
|
||||||
pub mod smallbox;
|
pub mod smallbox;
|
||||||
pub mod util;
|
pub mod util;
|
||||||
|
|
||||||
|
pub use cachepadded::CachePadded;
|
||||||
pub use util::can_transmute;
|
pub use util::can_transmute;
|
||||||
|
|
23
src/ptr.rs
23
src/ptr.rs
|
@ -6,7 +6,7 @@ use core::{
|
||||||
num::NonZero,
|
num::NonZero,
|
||||||
ops::{Deref, DerefMut},
|
ops::{Deref, DerefMut},
|
||||||
ptr::NonNull,
|
ptr::NonNull,
|
||||||
sync::atomic::{self, AtomicPtr, AtomicUsize},
|
sync::atomic::{self, AtomicPtr},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
|
@ -203,25 +203,40 @@ impl<T, const BITS: u8> TaggedAtomicPtr<T, BITS> {
|
||||||
|
|
||||||
// TODO: switch to fetch_or when stable
|
// TODO: switch to fetch_or when stable
|
||||||
// let old_ptr = self.ptr.fetch_or(tag & mask, order);
|
// let old_ptr = self.ptr.fetch_or(tag & mask, order);
|
||||||
|
#[cfg(feature = "nightly")]
|
||||||
|
{
|
||||||
|
let old_ptr = self.ptr.fetch_or(tag & mask, order);
|
||||||
|
old_ptr.addr() & mask
|
||||||
|
}
|
||||||
|
#[cfg(not(feature = "nightly"))]
|
||||||
|
{
|
||||||
|
use core::sync::atomic::AtomicUsize;
|
||||||
let ptr = unsafe { AtomicUsize::from_ptr(self.ptr.as_ptr() as *mut usize) };
|
let ptr = unsafe { AtomicUsize::from_ptr(self.ptr.as_ptr() as *mut usize) };
|
||||||
let old_ptr = ptr.fetch_or(tag & mask, order);
|
let old_ptr = ptr.fetch_or(tag & mask, order);
|
||||||
|
|
||||||
old_ptr & mask
|
old_ptr & mask
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// returns the tag and clears it
|
/// returns the tag and clears it
|
||||||
pub fn take_tag(&self, order: atomic::Ordering) -> usize {
|
pub fn take_tag(&self, order: atomic::Ordering) -> usize {
|
||||||
let mask = Self::mask();
|
let mask = Self::mask();
|
||||||
|
|
||||||
// TODO: switch to fetch_and when stable
|
#[cfg(feature = "nightly")]
|
||||||
// let old_ptr = self.ptr.fetch_and(!mask, order);
|
{
|
||||||
|
let old_ptr = self.ptr.fetch_and(!mask, order);
|
||||||
|
old_ptr.addr() & mask
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "nightly"))]
|
||||||
|
{
|
||||||
|
use core::sync::atomic::AtomicUsize;
|
||||||
let ptr = unsafe { AtomicUsize::from_ptr(self.ptr.as_ptr() as *mut usize) };
|
let ptr = unsafe { AtomicUsize::from_ptr(self.ptr.as_ptr() as *mut usize) };
|
||||||
let old_ptr = ptr.fetch_and(!mask, order);
|
let old_ptr = ptr.fetch_and(!mask, order);
|
||||||
|
|
||||||
old_ptr & mask
|
old_ptr & mask
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// returns tag
|
/// returns tag
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
|
Loading…
Reference in a new issue