On Wed Jul 16, 2025 at 5:48 PM CEST, Boqun Feng wrote:
On Wed, Jul 16, 2025 at 05:36:05PM +0200, Benno Lossin wrote:
[..]
quoted
quoted
I have a better solution:
in ops.rs
pub struct AtomicRepr<T: AtomicImpl>(UnsafeCell<T>)
impl AtomicArithmeticOps for i32 {
// a *safe* function
fn atomic_add(a: &AtomicRepr, v: i32) {
...
}
}
in generic.rs
pub struct Atomic<T>(AtoimcRepr<T::Repr>);
impl<T: AtomicAdd> Atomic<T> {
fn add(&self, v: .., ...) {
T::Repr::atomic_add(&self.0, ...);
}
}
see:
https://git.kernel.org/pub/scm/linux/kernel/git/boqun/linux.git/log/?h=rust-atomic-impl
Hmm what does the additional indirection give you?
What additional indirection you mean? You cannot make atomic_add() safe
with only `UnsafeCell<T::Repr>`.
What is the advantage of making it safe? It just moves the safety
comments into `ops.rs` which makes it harder to read due to the macros.
---
Cheers,
Benno