fix(napi): ThreadsafeFunctionHandle never being dropped (#1530)
This commit is contained in:
parent
c8bd8924e2
commit
5605bdf7fc
1 changed files with 6 additions and 8 deletions
|
@ -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<T: 'static, ES: ErrorStrategy::T> ThreadsafeFunction<T, ES> {
|
|||
.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<T: 'static, ES: ErrorStrategy::T> ThreadsafeFunction<T, ES> {
|
|||
.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(())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue