From 5605bdf7fcbe8781ae5587f96fa9141168be0a3d Mon Sep 17 00:00:00 2001 From: LongYinan Date: Mon, 20 Mar 2023 18:01:09 +0800 Subject: [PATCH] fix(napi): ThreadsafeFunctionHandle never being dropped (#1530) --- crates/napi/src/threadsafe_function.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/crates/napi/src/threadsafe_function.rs b/crates/napi/src/threadsafe_function.rs index 063aa555..8d1f8784 100644 --- a/crates/napi/src/threadsafe_function.rs +++ b/crates/napi/src/threadsafe_function.rs @@ -117,9 +117,7 @@ impl ThreadsafeFunctionHandle { } fn get_raw(&self) -> sys::napi_threadsafe_function { - let raw = self.raw.load(Ordering::SeqCst); - assert!(!raw.is_null()); - raw + self.raw.load(Ordering::SeqCst) } fn set_raw(&self, raw: sys::napi_threadsafe_function) { @@ -133,7 +131,7 @@ impl Drop for ThreadsafeFunctionHandle { .aborted .read() .expect("Threadsafe Function aborted lock failed"); - if !*aborted_guard && self.referred.load(Ordering::Acquire) { + if !*aborted_guard { let release_status = unsafe { sys::napi_release_threadsafe_function( self.get_raw(), @@ -358,9 +356,9 @@ impl ThreadsafeFunction { .aborted .read() .expect("Threadsafe Function aborted lock failed"); - if !*aborted_guard && !self.handle.referred.load(Ordering::Acquire) { + if !*aborted_guard && !self.handle.referred.load(Ordering::Relaxed) { check_status!(unsafe { sys::napi_ref_threadsafe_function(env.0, self.handle.get_raw()) })?; - self.handle.referred.store(true, Ordering::Release); + self.handle.referred.store(true, Ordering::Relaxed); } Ok(()) } @@ -373,9 +371,9 @@ impl ThreadsafeFunction { .aborted .read() .expect("Threadsafe Function aborted lock failed"); - if !*aborted_guard && self.handle.referred.load(Ordering::Acquire) { + if !*aborted_guard && self.handle.referred.load(Ordering::Relaxed) { check_status!(unsafe { sys::napi_unref_threadsafe_function(env.0, self.handle.get_raw()) })?; - self.handle.referred.store(false, Ordering::Release); + self.handle.referred.store(false, Ordering::Relaxed); } Ok(()) }