mirror of
https://github.com/Psychotoxical/psysonic.git
synced 2026-07-21 23:05:46 +00:00
fix(perf): use mach2 for macOS host CPU tick Mach ports (#932)
Replace deprecated libc mach_host_self/mach_task_self with mach2 APIs while keeping host_processor_info on libc (no mach2 binding). Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.com>
This commit is contained in:
Generated
+1
@@ -4064,6 +4064,7 @@ dependencies = [
|
|||||||
"image",
|
"image",
|
||||||
"libc",
|
"libc",
|
||||||
"lofty",
|
"lofty",
|
||||||
|
"mach2",
|
||||||
"md5",
|
"md5",
|
||||||
"psysonic-analysis",
|
"psysonic-analysis",
|
||||||
"psysonic-audio",
|
"psysonic-audio",
|
||||||
|
|||||||
@@ -80,6 +80,9 @@ webp = "0.3"
|
|||||||
[target.'cfg(unix)'.dependencies]
|
[target.'cfg(unix)'.dependencies]
|
||||||
libc = "0.2"
|
libc = "0.2"
|
||||||
|
|
||||||
|
[target.'cfg(target_os = "macos")'.dependencies]
|
||||||
|
mach2 = "0.5"
|
||||||
|
|
||||||
[target.'cfg(target_os = "linux")'.dependencies]
|
[target.'cfg(target_os = "linux")'.dependencies]
|
||||||
zbus = { version = "5.15", default-features = false, features = ["blocking-api", "async-io"] }
|
zbus = { version = "5.15", default-features = false, features = ["blocking-api", "async-io"] }
|
||||||
# Match wry/tauri’s WebKitGTK stack — used only to turn off kinetic wheel scrolling.
|
# Match wry/tauri’s WebKitGTK stack — used only to turn off kinetic wheel scrolling.
|
||||||
|
|||||||
@@ -369,17 +369,23 @@ mod macos {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn read_host_total_cpu_ticks() -> u64 {
|
fn read_host_total_cpu_ticks() -> u64 {
|
||||||
|
use mach2::kern_return::KERN_SUCCESS;
|
||||||
|
use mach2::mach_init::mach_host_self;
|
||||||
|
use mach2::traps::mach_task_self;
|
||||||
|
use mach2::vm::mach_vm_deallocate;
|
||||||
|
use mach2::vm_types::{mach_vm_address_t, mach_vm_size_t};
|
||||||
|
|
||||||
let mut num_cpus: u32 = 0;
|
let mut num_cpus: u32 = 0;
|
||||||
let mut cpu_info: *mut i32 = std::ptr::null_mut();
|
let mut cpu_info: *mut i32 = std::ptr::null_mut();
|
||||||
let mut num_cpu_info: u32 = 0;
|
let mut num_cpu_info: u32 = 0;
|
||||||
let ok = unsafe {
|
let ok = unsafe {
|
||||||
libc::host_processor_info(
|
libc::host_processor_info(
|
||||||
libc::mach_host_self(),
|
mach_host_self(),
|
||||||
libc::PROCESSOR_CPU_LOAD_INFO,
|
libc::PROCESSOR_CPU_LOAD_INFO,
|
||||||
&mut num_cpus,
|
&mut num_cpus,
|
||||||
&mut cpu_info,
|
&mut cpu_info,
|
||||||
&mut num_cpu_info,
|
&mut num_cpu_info,
|
||||||
) == libc::KERN_SUCCESS
|
) == KERN_SUCCESS
|
||||||
};
|
};
|
||||||
if !ok || cpu_info.is_null() {
|
if !ok || cpu_info.is_null() {
|
||||||
return 0;
|
return 0;
|
||||||
@@ -392,8 +398,11 @@ mod macos {
|
|||||||
};
|
};
|
||||||
unsafe {
|
unsafe {
|
||||||
let size = num_cpu_info as usize * mem::size_of::<i32>();
|
let size = num_cpu_info as usize * mem::size_of::<i32>();
|
||||||
#[allow(deprecated)]
|
mach_vm_deallocate(
|
||||||
libc::vm_deallocate(libc::mach_task_self(), cpu_info as _, size);
|
mach_task_self(),
|
||||||
|
cpu_info as mach_vm_address_t,
|
||||||
|
size as mach_vm_size_t,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
total
|
total
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user