From 3deae16442b0fe40bd3003c1f71dd3b155f99039 Mon Sep 17 00:00:00 2001 From: LongYinan Date: Mon, 6 Nov 2023 13:59:54 +0800 Subject: [PATCH] fix(napi): add tokio cleanup hook for more platforms (#1790) --- crates/napi/src/bindgen_runtime/module_register.rs | 4 ++-- crates/napi/src/tokio_runtime.rs | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/napi/src/bindgen_runtime/module_register.rs b/crates/napi/src/bindgen_runtime/module_register.rs index 2dbdd090..fecbfef6 100644 --- a/crates/napi/src/bindgen_runtime/module_register.rs +++ b/crates/napi/src/bindgen_runtime/module_register.rs @@ -6,7 +6,7 @@ use std::ptr; #[cfg(all(feature = "napi4", not(target_os = "wasi")))] use std::sync::atomic::AtomicPtr; #[cfg(all( - any(target_os = "windows", target_os = "freebsd"), + not(any(target_os = "macos", target_os = "wasi")), feature = "napi4", feature = "tokio_rt" ))] @@ -463,7 +463,7 @@ pub unsafe extern "C" fn napi_register_module_v1( } #[cfg(all( - any(target_os = "windows", target_os = "freebsd"), + not(any(target_os = "macos", target_os = "wasi")), feature = "napi4", feature = "tokio_rt" ))] diff --git a/crates/napi/src/tokio_runtime.rs b/crates/napi/src/tokio_runtime.rs index c89fa99b..e76dd0bf 100644 --- a/crates/napi/src/tokio_runtime.rs +++ b/crates/napi/src/tokio_runtime.rs @@ -23,14 +23,14 @@ fn create_runtime() -> Option { pub(crate) static RT: Lazy>> = Lazy::new(|| RwLock::new(create_runtime())); -#[cfg(any(target_os = "windows", target_os = "freebsd"))] +#[cfg(not(any(target_os = "macos", target_os = "wasi")))] static RT_REFERENCE_COUNT: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); /// Ensure that the Tokio runtime is initialized. /// In windows the Tokio runtime will be dropped when Node env exits. /// But in Electron renderer process, the Node env will exits and recreate when the window reloads. /// So we need to ensure that the Tokio runtime is initialized when the Node env is created. -#[cfg(any(target_os = "windows", target_os = "freebsd"))] +#[cfg(not(any(target_os = "macos", target_os = "wasi")))] pub(crate) fn ensure_runtime() { use std::sync::atomic::Ordering; @@ -42,7 +42,7 @@ pub(crate) fn ensure_runtime() { RT_REFERENCE_COUNT.fetch_add(1, Ordering::Relaxed); } -#[cfg(any(target_os = "windows", target_os = "freebsd"))] +#[cfg(not(any(target_os = "macos", target_os = "wasi")))] pub(crate) unsafe extern "C" fn drop_runtime(_arg: *mut std::ffi::c_void) { use std::sync::atomic::Ordering;