1
0
Fork 0
forked from wry/wry

workspace: move crates under crates

This commit is contained in:
kossLAN 2026-05-29 18:55:59 -04:00
parent 0016bc8cf0
commit 6393fdf3c0
No known key found for this signature in database
354 changed files with 102 additions and 102 deletions

View file

@ -0,0 +1,42 @@
use {
linearize::Linearize,
std::{
marker::PhantomData,
sync::atomic::{AtomicUsize, Ordering},
},
};
pub struct AtomicEnum<T> {
v: AtomicUsize,
_phantom: PhantomData<T>,
}
impl<T> Default for AtomicEnum<T>
where
T: Default + Linearize + Copy,
{
fn default() -> Self {
Self::new(T::default())
}
}
impl<T> AtomicEnum<T>
where
T: Linearize + Copy,
{
pub fn new(t: T) -> Self {
Self {
v: AtomicUsize::new(t.linearize()),
_phantom: Default::default(),
}
}
#[allow(dead_code)]
pub fn load(&self, ordering: Ordering) -> T {
unsafe { T::from_linear_unchecked(self.v.load(ordering)) }
}
pub fn store(&self, t: T, ordering: Ordering) {
self.v.store(t.linearize(), ordering);
}
}