texture freeing + render updates done a bit nicer
This commit is contained in:
27
src/util/refcount.rs
Normal file
27
src/util/refcount.rs
Normal file
@@ -0,0 +1,27 @@
|
||||
use std::sync::{
|
||||
Arc,
|
||||
atomic::{AtomicU32, Ordering},
|
||||
mpsc::Sender,
|
||||
};
|
||||
|
||||
pub struct RefCounter(Arc<AtomicU32>);
|
||||
|
||||
impl RefCounter {
|
||||
pub fn new() -> Self {
|
||||
Self(Arc::new(0.into()))
|
||||
}
|
||||
pub fn refs(&self) -> u32 {
|
||||
self.0.load(Ordering::Acquire)
|
||||
}
|
||||
pub fn drop(&mut self) -> bool {
|
||||
let refs = self.0.fetch_sub(1, Ordering::Release);
|
||||
refs == 0
|
||||
}
|
||||
}
|
||||
|
||||
impl Clone for RefCounter {
|
||||
fn clone(&self) -> Self {
|
||||
self.0.fetch_add(1, Ordering::Release);
|
||||
Self(self.0.clone())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user