X-Git-Url: https://git.nihav.org/?a=blobdiff_plain;f=nihav-core%2Fsrc%2Frefs.rs;h=292c8887d4cf376c3413d0faf42e37e10cd10d6c;hb=93bbc2b0582d4199cef6642924dca7c95bfe135a;hp=de1c4fc3b5f7809120bdce7b0e93a82105892287;hpb=e243ceb4d694cc08767ad70027bb6963f4cefea3;p=nihav.git diff --git a/nihav-core/src/refs.rs b/nihav-core/src/refs.rs index de1c4fc..292c888 100644 --- a/nihav-core/src/refs.rs +++ b/nihav-core/src/refs.rs @@ -18,7 +18,7 @@ impl NABufferData { obj.refs.fetch_add(1, Ordering::SeqCst); } fn dec_refs(obj: &mut Self) -> bool { - obj.refs.fetch_sub(1, Ordering::SeqCst) == 0 + obj.refs.fetch_sub(1, Ordering::SeqCst) == 1 } fn get_num_refs(obj: &Self) -> usize { obj.refs.load(Ordering::Relaxed) @@ -35,6 +35,9 @@ pub struct NABufferRef { ptr: *mut NABufferData, } +unsafe impl Sync for NABufferRef {} +unsafe impl Send for NABufferRef {} + impl NABufferRef { pub fn new(val: T) -> Self { let bdata = NABufferData::new(val); @@ -83,7 +86,8 @@ impl Drop for NABufferRef { fn drop(&mut self) { unsafe { if NABufferData::dec_refs(self.ptr.as_mut().unwrap()) { - std::ptr::drop_in_place(self.ptr); + let data = Box::from_raw(self.ptr); + std::mem::drop(data); } } }