commonlibsse_ng\re\b/
BSIntrusiveRefCounted.rs1use core::sync::atomic::{AtomicU32, Ordering};
2
3#[repr(C)]
4#[derive(Debug, Default)]
5pub struct BSIntrusiveRefCounted {
6 pub refCount: AtomicU32,
7}
8const _: () = assert!(core::mem::size_of::<BSIntrusiveRefCounted>() == 0x4);
9
10impl BSIntrusiveRefCounted {
11 #[inline]
12 pub const fn new() -> Self {
13 Self { refCount: AtomicU32::new(0) }
14 }
15}
16
17pub trait BSIntrusiveRefCountedTrait {
18 fn inc_ref(&self) -> u32;
24
25 fn dec_ref(&self) -> u32;
31}
32
33impl BSIntrusiveRefCountedTrait for BSIntrusiveRefCounted {
34 #[inline]
35 fn inc_ref(&self) -> u32 {
36 self.refCount.fetch_add(1, Ordering::AcqRel) + 1
38 }
39
40 #[inline]
41 fn dec_ref(&self) -> u32 {
42 self.refCount.fetch_sub(1, Ordering::AcqRel) - 1
44 }
45}