SeqCst->Relaxed for proc_macro bridge counter.

Relaxed is enough here.
This commit is contained in:
Mara Bos 2024-03-19 14:57:19 +01:00
parent 5e4cc6f694
commit bf3debe9d7

View file

@ -21,7 +21,7 @@ impl<T> OwnedStore<T> {
pub(super) fn new(counter: &'static AtomicU32) -> Self {
// Ensure the handle counter isn't 0, which would panic later,
// when `NonZero::new` (aka `Handle::new`) is called in `alloc`.
assert_ne!(counter.load(Ordering::SeqCst), 0);
assert_ne!(counter.load(Ordering::Relaxed), 0);
OwnedStore { counter, data: BTreeMap::new() }
}
@ -29,7 +29,7 @@ impl<T> OwnedStore<T> {
impl<T> OwnedStore<T> {
pub(super) fn alloc(&mut self, x: T) -> Handle {
let counter = self.counter.fetch_add(1, Ordering::SeqCst);
let counter = self.counter.fetch_add(1, Ordering::Relaxed);
let handle = Handle::new(counter).expect("`proc_macro` handle counter overflowed");
assert!(self.data.insert(handle, x).is_none());
handle