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 {
|
fn get_raw(&self) -> sys::napi_threadsafe_function {
|
||||||
let raw = self.raw.load(Ordering::SeqCst);
|
self.raw.load(Ordering::SeqCst)
|
||||||
assert!(!raw.is_null());
|
|
||||||
raw
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_raw(&self, raw: sys::napi_threadsafe_function) {
|
fn set_raw(&self, raw: sys::napi_threadsafe_function) {
|
||||||
|
@ -133,7 +131,7 @@ impl Drop for ThreadsafeFunctionHandle {
|
||||||
.aborted
|
.aborted
|
||||||
.read()
|
.read()
|
||||||
.expect("Threadsafe Function aborted lock failed");
|
.expect("Threadsafe Function aborted lock failed");
|
||||||
if !*aborted_guard && self.referred.load(Ordering::Acquire) {
|
if !*aborted_guard {
|
||||||
let release_status = unsafe {
|
let release_status = unsafe {
|
||||||
sys::napi_release_threadsafe_function(
|
sys::napi_release_threadsafe_function(
|
||||||
self.get_raw(),
|
self.get_raw(),
|
||||||
|
@ -358,9 +356,9 @@ impl<T: 'static, ES: ErrorStrategy::T> ThreadsafeFunction<T, ES> {
|
||||||
.aborted
|
.aborted
|
||||||
.read()
|
.read()
|
||||||
.expect("Threadsafe Function aborted lock failed");
|
.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()) })?;
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -373,9 +371,9 @@ impl<T: 'static, ES: ErrorStrategy::T> ThreadsafeFunction<T, ES> {
|
||||||
.aborted
|
.aborted
|
||||||
.read()
|
.read()
|
||||||
.expect("Threadsafe Function aborted lock failed");
|
.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()) })?;
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue