mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
chore(node-api): reuse SendPtr (#21567)
Pending review items from https://github.com/denoland/deno/pull/21406
This commit is contained in:
parent
c481ff7d81
commit
94c70fd719
2 changed files with 9 additions and 10 deletions
|
@ -3,6 +3,7 @@
|
||||||
use deno_runtime::deno_napi::*;
|
use deno_runtime::deno_napi::*;
|
||||||
|
|
||||||
use crate::check_env;
|
use crate::check_env;
|
||||||
|
use crate::napi::threadsafe_functions::SendPtr;
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct AsyncWork {
|
pub struct AsyncWork {
|
||||||
|
@ -64,10 +65,6 @@ fn napi_queue_async_work(
|
||||||
return napi_invalid_arg;
|
return napi_invalid_arg;
|
||||||
};
|
};
|
||||||
|
|
||||||
#[repr(transparent)]
|
|
||||||
struct SendPtr<T>(*const T);
|
|
||||||
unsafe impl<T> Send for SendPtr<T> {}
|
|
||||||
unsafe impl<T> Sync for SendPtr<T> {}
|
|
||||||
let send_env = SendPtr(env_ptr);
|
let send_env = SendPtr(env_ptr);
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
|
|
@ -9,6 +9,12 @@ use std::ptr::NonNull;
|
||||||
use std::sync::atomic::AtomicUsize;
|
use std::sync::atomic::AtomicUsize;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
#[repr(transparent)]
|
||||||
|
pub struct SendPtr<T>(pub *const T);
|
||||||
|
|
||||||
|
unsafe impl<T> Send for SendPtr<T> {}
|
||||||
|
unsafe impl<T> Sync for SendPtr<T> {}
|
||||||
|
|
||||||
static TS_FN_ID_COUNTER: Lazy<AtomicUsize> = Lazy::new(|| AtomicUsize::new(0));
|
static TS_FN_ID_COUNTER: Lazy<AtomicUsize> = Lazy::new(|| AtomicUsize::new(0));
|
||||||
|
|
||||||
pub struct TsFn {
|
pub struct TsFn {
|
||||||
|
@ -86,11 +92,6 @@ impl TsFn {
|
||||||
pub fn call(&self, data: *mut c_void, is_blocking: bool) {
|
pub fn call(&self, data: *mut c_void, is_blocking: bool) {
|
||||||
let js_func = self.maybe_func.clone();
|
let js_func = self.maybe_func.clone();
|
||||||
|
|
||||||
#[repr(transparent)]
|
|
||||||
struct SendPtr<T>(*const T);
|
|
||||||
unsafe impl<T> Send for SendPtr<T> {}
|
|
||||||
unsafe impl<T> Sync for SendPtr<T> {}
|
|
||||||
|
|
||||||
let env = SendPtr(self.env);
|
let env = SendPtr(self.env);
|
||||||
let context = SendPtr(self.context);
|
let context = SendPtr(self.context);
|
||||||
let data = SendPtr(data);
|
let data = SendPtr(data);
|
||||||
|
@ -146,7 +147,8 @@ impl TsFn {
|
||||||
context: SendPtr<c_void>,
|
context: SendPtr<c_void>,
|
||||||
data: SendPtr<c_void>,
|
data: SendPtr<c_void>,
|
||||||
) {
|
) {
|
||||||
// SAFETY: We're calling the provided callback with valid args
|
// SAFETY: env is valid for the duration of the callback.
|
||||||
|
// data lifetime is users responsibility.
|
||||||
unsafe {
|
unsafe {
|
||||||
call_js_cb(
|
call_js_cb(
|
||||||
env.0 as _,
|
env.0 as _,
|
||||||
|
|
Loading…
Add table
Reference in a new issue