From 11a44b8c98bdefa046f43e589accb371120eb9f6 Mon Sep 17 00:00:00 2001 From: Nikolai Vazquez Date: Mon, 25 Nov 2024 17:36:16 -0500 Subject: [PATCH] Use `mach2` crate for `mach_thread_self` example The `libc` crate has deprecated its Mach API in favor of this crate. --- examples/Cargo.toml | 3 +++ examples/benches/threads.rs | 13 ++++--------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/examples/Cargo.toml b/examples/Cargo.toml index c33fbf8..028895a 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -34,6 +34,9 @@ twox-hash = { version = "1.6", optional = true } [target.'cfg(unix)'.dependencies] libc = { workspace = true } +[target.'cfg(target_os = "macos")'.dependencies] +mach2 = "0.4" + [target.'cfg(any(windows, target_os = "linux", target_os = "android"))'.dependencies] winapi = { version = "0.3.9", features = ["processthreadsapi"] } diff --git a/examples/benches/threads.rs b/examples/benches/threads.rs index aa7d5ee..cf41a0b 100644 --- a/examples/benches/threads.rs +++ b/examples/benches/threads.rs @@ -268,22 +268,17 @@ mod thread_id { #[cfg(target_os = "macos")] #[divan::bench] fn mach_thread_self() -> impl Drop { - struct Thread(libc::thread_t); + struct Thread(mach2::mach_types::thread_port_t); impl Drop for Thread { fn drop(&mut self) { - extern "C" { - fn mach_port_deallocate( - task: libc::mach_port_t, - name: libc::mach_port_t, - ) -> libc::kern_return_t; + unsafe { + mach2::mach_port::mach_port_deallocate(mach2::traps::mach_task_self(), self.0); } - - unsafe { mach_port_deallocate(libc::mach_task_self(), self.0) }; } } - Thread(unsafe { libc::mach_thread_self() }) + Thread(unsafe { mach2::mach_init::mach_thread_self() }) } // https://man7.org/linux/man-pages/man2/gettid.2.html