summaryrefslogtreecommitdiffstats
path: root/vendor/crossbeam-epoch/src/deferred.rs
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/crossbeam-epoch/src/deferred.rs')
-rw-r--r--vendor/crossbeam-epoch/src/deferred.rs19
1 files changed, 14 insertions, 5 deletions
diff --git a/vendor/crossbeam-epoch/src/deferred.rs b/vendor/crossbeam-epoch/src/deferred.rs
index c33d51502..2f3d79fdf 100644
--- a/vendor/crossbeam-epoch/src/deferred.rs
+++ b/vendor/crossbeam-epoch/src/deferred.rs
@@ -29,6 +29,15 @@ impl fmt::Debug for Deferred {
}
impl Deferred {
+ pub(crate) const NO_OP: Self = {
+ fn no_op_call(_raw: *mut u8) {}
+ Self {
+ call: no_op_call,
+ data: MaybeUninit::uninit(),
+ _marker: PhantomData,
+ }
+ };
+
/// Constructs a new `Deferred` from a `FnOnce()`.
pub(crate) fn new<F: FnOnce()>(f: F) -> Self {
let size = mem::size_of::<F>();
@@ -37,10 +46,10 @@ impl Deferred {
unsafe {
if size <= mem::size_of::<Data>() && align <= mem::align_of::<Data>() {
let mut data = MaybeUninit::<Data>::uninit();
- ptr::write(data.as_mut_ptr() as *mut F, f);
+ ptr::write(data.as_mut_ptr().cast::<F>(), f);
unsafe fn call<F: FnOnce()>(raw: *mut u8) {
- let f: F = ptr::read(raw as *mut F);
+ let f: F = ptr::read(raw.cast::<F>());
f();
}
@@ -52,12 +61,12 @@ impl Deferred {
} else {
let b: Box<F> = Box::new(f);
let mut data = MaybeUninit::<Data>::uninit();
- ptr::write(data.as_mut_ptr() as *mut Box<F>, b);
+ ptr::write(data.as_mut_ptr().cast::<Box<F>>(), b);
unsafe fn call<F: FnOnce()>(raw: *mut u8) {
// It's safe to cast `raw` from `*mut u8` to `*mut Box<F>`, because `raw` is
// originally derived from `*mut Box<F>`.
- let b: Box<F> = ptr::read(raw as *mut Box<F>);
+ let b: Box<F> = ptr::read(raw.cast::<Box<F>>());
(*b)();
}
@@ -74,7 +83,7 @@ impl Deferred {
#[inline]
pub(crate) fn call(mut self) {
let call = self.call;
- unsafe { call(self.data.as_mut_ptr() as *mut u8) };
+ unsafe { call(self.data.as_mut_ptr().cast::<u8>()) };
}
}