Port to windows-sys (#27)

This commit is contained in:
John Nunley 2022-11-26 21:14:01 -08:00 committed by GitHub
parent f835f75f39
commit de1071784e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 11 deletions

View File

@ -35,10 +35,11 @@ default-features = false
[target.'cfg(windows)'.dependencies]
blocking = "1.0.0"
[target.'cfg(windows)'.dependencies.winapi]
version = "0.3.9"
[target.'cfg(windows)'.dependencies.windows-sys]
version = "0.42"
default-features = false
features = [
"winbase",
"winnt"
]
"Win32_Foundation",
"Win32_System_Threading",
"Win32_System_WindowsProgramming"
]

View File

@ -145,12 +145,16 @@ impl Child {
cfg_if::cfg_if! {
if #[cfg(windows)] {
use std::ffi::c_void;
use std::os::windows::io::AsRawHandle;
use std::sync::mpsc;
use winapi::um::{
winbase::{RegisterWaitForSingleObject, INFINITE},
winnt::{BOOLEAN, HANDLE, PVOID, WT_EXECUTEINWAITTHREAD, WT_EXECUTEONLYONCE},
use windows_sys::Win32::{
System::{
Threading::{RegisterWaitForSingleObject, WT_EXECUTEINWAITTHREAD, WT_EXECUTEONLYONCE},
WindowsProgramming::INFINITE,
},
Foundation::{BOOLEAN, HANDLE},
};
// This channel is used to simulate SIGCHLD on Windows.
@ -168,12 +172,12 @@ impl Child {
// Called when a child exits.
unsafe extern "system" fn callback(_: PVOID, _: BOOLEAN) {
unsafe extern "system" fn callback(_: *mut c_void, _: BOOLEAN) {
callback_channel().0.try_send(()).ok();
}
// Register this child process to invoke `callback` on exit.
let mut wait_object = std::ptr::null_mut();
let mut wait_object = 0;
let ret = unsafe {
RegisterWaitForSingleObject(
&mut wait_object,

View File

@ -385,7 +385,7 @@ fn child_status_preserved_with_kill_on_drop() {
#[cfg(windows)]
fn child_as_raw_handle() {
use std::os::windows::io::AsRawHandle;
use winapi::um::processthreadsapi::GetProcessId;
use windows_sys::Win32::System::Threading::GetProcessId;
future::block_on(async {
let p = Command::new("cmd.exe")