Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(node): implement libuv APIs needed to support npm:sqlite3 #25893

Merged
merged 17 commits into from
Oct 2, 2024
Prev Previous commit
Next Next commit
Windows?
  • Loading branch information
nathanwhit committed Sep 21, 2024
commit 3cb98d33dc9b8a9fcaa58ecc3948c82eff9bedad
53 changes: 44 additions & 9 deletions cli/napi/js_native_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3615,9 +3615,8 @@ fn napi_is_detached_arraybuffer(

mod uv {
use deno_runtime::deno_napi::*;
use std::mem::MaybeUninit;
use std::ptr::addr_of_mut;
use std::{mem::MaybeUninit, sync::atomic::AtomicBool};
// use crate::

fn cvt(res: c_int) -> c_int {
if libc::EDOM > 0 {
Expand Down Expand Up @@ -3646,10 +3645,9 @@ mod uv {
#[cfg(unix)]
mod mutex {
use super::*;
type uv_mutex_t = libc::pthread_mutex_t;
#[no_mangle]
unsafe extern "C" fn uv_mutex_init(
lock: *mut libc::pthread_mutex_t,
) -> c_int {
unsafe extern "C" fn uv_mutex_init(lock: *mut uv_mutex_t) -> c_int {
use std::mem::MaybeUninit;
let mut attr = MaybeUninit::<libc::pthread_mutexattr_t>::uninit();
unsafe {
Expand All @@ -3667,26 +3665,60 @@ mod uv {
}

#[no_mangle]
unsafe extern "C" fn uv_mutex_lock(lock: *mut libc::pthread_mutex_t) {
unsafe extern "C" fn uv_mutex_lock(lock: *mut uv_mutex_t) {
unsafe {
assert_ok(libc::pthread_mutex_lock(lock));
}
}

#[no_mangle]
unsafe extern "C" fn uv_mutex_unlock(lock: *mut libc::pthread_mutex_t) {
unsafe extern "C" fn uv_mutex_unlock(lock: *mut uv_mutex_t) {
unsafe {
assert_ok(libc::pthread_mutex_unlock(lock));
}
}

#[no_mangle]
unsafe extern "C" fn uv_mutex_destroy(lock: *mut libc::pthread_mutex_t) {
unsafe extern "C" fn uv_mutex_destroy(lock: *mut uv_mutex_t) {
unsafe {
assert_ok(libc::pthread_mutex_destroy(lock));
}
}
}
#[cfg(windows)]
mod mutex {
use windows_sys::Win32::System::Threading as win;
type uv_mutex_t = win::CRITICAL_SECTION;

#[no_mangle]
unsafe extern "C" fn uv_mutex_init(lock: *mut uv_mutex_t) -> c_int {
unsafe {
win::InitializeCriticalSection(lock);
}
0
}

#[no_mangle]
unsafe extern "C" fn uv_mutex_lock(lock: *mut uv_mutex_t) {
unsafe {
win::EnterCriticalSection(lock);
}
}

#[no_mangle]
unsafe extern "C" fn uv_mutex_unlock(lock: *mut uv_mutex_t) {
unsafe {
win::LeaveCriticalSection(lock);
}
}

#[no_mangle]
unsafe extern "C" fn uv_mutex_destroy(lock: *mut uv_mutex_t) {
unsafe {
win::DeleteCriticalSection(lock);
}
}
}

#[repr(C)]
#[derive(Clone, Copy, Debug)]
Expand All @@ -3713,6 +3745,8 @@ mod uv {
UV_HANDLE_TYPE_MAX,
}

const UV_HANDLE_SIZE: usize = 96;

#[repr(C)]
struct uv_handle_t {
// public members
Expand All @@ -3721,7 +3755,8 @@ mod uv {
pub r#type: uv_handle_type,

_padding: [MaybeUninit<u8>; const {
96 - size_of::<*mut c_void>()
UV_HANDLE_SIZE
- size_of::<*mut c_void>()
- size_of::<*mut uv_loop_t>()
- size_of::<uv_handle_type>()
}],
Expand Down