From 90167591269d10039d44471c7d10c16ff70f4cd7 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Sat, 8 Jan 2022 15:22:50 +0900 Subject: [PATCH] Fix build error on cfg(crossbeam_loom) --- crossbeam-utils/src/atomic/atomic_cell.rs | 75 +++++++++++++++-------- 1 file changed, 50 insertions(+), 25 deletions(-) diff --git a/crossbeam-utils/src/atomic/atomic_cell.rs b/crossbeam-utils/src/atomic/atomic_cell.rs index 325cf3797..427b7e7c5 100644 --- a/crossbeam-utils/src/atomic/atomic_cell.rs +++ b/crossbeam-utils/src/atomic/atomic_cell.rs @@ -313,11 +313,16 @@ macro_rules! impl_arithmetic { /// ``` #[inline] pub fn fetch_add(&self, val: $t) -> $t { - let _guard = lock(self.value.get() as usize).write(); - let value = unsafe { &mut *(self.value.get()) }; - let old = *value; - *value = value.wrapping_add(val); - old + #[cfg(crossbeam_loom)] + unimplemented!("loom does not support non-atomic atomic ops"); + #[cfg(not(crossbeam_loom))] + { + let _guard = lock(self.value.get() as usize).write(); + let value = unsafe { &mut *(self.value.get()) }; + let old = *value; + *value = value.wrapping_add(val); + old + } } /// Decrements the current value by `val` and returns the previous value. @@ -336,11 +341,16 @@ macro_rules! impl_arithmetic { /// ``` #[inline] pub fn fetch_sub(&self, val: $t) -> $t { - let _guard = lock(self.value.get() as usize).write(); - let value = unsafe { &mut *(self.value.get()) }; - let old = *value; - *value = value.wrapping_sub(val); - old + #[cfg(crossbeam_loom)] + unimplemented!("loom does not support non-atomic atomic ops"); + #[cfg(not(crossbeam_loom))] + { + let _guard = lock(self.value.get() as usize).write(); + let value = unsafe { &mut *(self.value.get()) }; + let old = *value; + *value = value.wrapping_sub(val); + old + } } /// Applies bitwise "and" to the current value and returns the previous value. @@ -357,11 +367,16 @@ macro_rules! impl_arithmetic { /// ``` #[inline] pub fn fetch_and(&self, val: $t) -> $t { - let _guard = lock(self.value.get() as usize).write(); - let value = unsafe { &mut *(self.value.get()) }; - let old = *value; - *value &= val; - old + #[cfg(crossbeam_loom)] + unimplemented!("loom does not support non-atomic atomic ops"); + #[cfg(not(crossbeam_loom))] + { + let _guard = lock(self.value.get() as usize).write(); + let value = unsafe { &mut *(self.value.get()) }; + let old = *value; + *value &= val; + old + } } /// Applies bitwise "or" to the current value and returns the previous value. @@ -378,11 +393,16 @@ macro_rules! impl_arithmetic { /// ``` #[inline] pub fn fetch_or(&self, val: $t) -> $t { - let _guard = lock(self.value.get() as usize).write(); - let value = unsafe { &mut *(self.value.get()) }; - let old = *value; - *value |= val; - old + #[cfg(crossbeam_loom)] + unimplemented!("loom does not support non-atomic atomic ops"); + #[cfg(not(crossbeam_loom))] + { + let _guard = lock(self.value.get() as usize).write(); + let value = unsafe { &mut *(self.value.get()) }; + let old = *value; + *value |= val; + old + } } /// Applies bitwise "xor" to the current value and returns the previous value. @@ -399,11 +419,16 @@ macro_rules! impl_arithmetic { /// ``` #[inline] pub fn fetch_xor(&self, val: $t) -> $t { - let _guard = lock(self.value.get() as usize).write(); - let value = unsafe { &mut *(self.value.get()) }; - let old = *value; - *value ^= val; - old + #[cfg(crossbeam_loom)] + unimplemented!("loom does not support non-atomic atomic ops"); + #[cfg(not(crossbeam_loom))] + { + let _guard = lock(self.value.get() as usize).write(); + let value = unsafe { &mut *(self.value.get()) }; + let old = *value; + *value ^= val; + old + } } } };