Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Amanieu committed Sep 20, 2022
1 parent b9612b3 commit 584a916
Show file tree
Hide file tree
Showing 6 changed files with 195 additions and 178 deletions.
2 changes: 1 addition & 1 deletion core/src/thread_parker/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
//! A simple spin lock based thread parker. Used on platforms without better
//! parking facilities available.
use core::sync::atomic::{AtomicBool, Ordering};
use core::hint::spin_loop;
use core::sync::atomic::{AtomicBool, Ordering};
use std::thread;
use std::time::Instant;

Expand Down
14 changes: 12 additions & 2 deletions core/src/thread_parker/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,22 @@ impl super::ThreadParkerT for ThreadParker {

impl ThreadParker {
/// Initializes the condvar to use CLOCK_MONOTONIC instead of CLOCK_REALTIME.
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "android", target_os = "espidf"))]
#[cfg(any(
target_os = "macos",
target_os = "ios",
target_os = "android",
target_os = "espidf"
))]
#[inline]
unsafe fn init(&self) {}

/// Initializes the condvar to use CLOCK_MONOTONIC instead of CLOCK_REALTIME.
#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "android", target_os = "espidf")))]
#[cfg(not(any(
target_os = "macos",
target_os = "ios",
target_os = "android",
target_os = "espidf"
)))]
#[inline]
unsafe fn init(&self) {
let mut attr = MaybeUninit::<libc::pthread_condattr_t>::uninit();
Expand Down
64 changes: 32 additions & 32 deletions core/src/thread_parker/windows/keyed_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,40 +55,40 @@ impl KeyedEvent {

#[allow(non_snake_case)]
pub fn create() -> Option<KeyedEvent> {
let ntdll = unsafe { GetModuleHandleA(b"ntdll.dll\0".as_ptr()) };
if ntdll == 0 {
return None;
}
let ntdll = unsafe { GetModuleHandleA(b"ntdll.dll\0".as_ptr()) };
if ntdll == 0 {
return None;
}

let NtCreateKeyedEvent =
unsafe { GetProcAddress(ntdll, b"NtCreateKeyedEvent\0".as_ptr())? };
let NtReleaseKeyedEvent =
unsafe { GetProcAddress(ntdll, b"NtReleaseKeyedEvent\0".as_ptr())? };
let NtWaitForKeyedEvent =
unsafe { GetProcAddress(ntdll, b"NtWaitForKeyedEvent\0".as_ptr())?};

let NtCreateKeyedEvent: extern "system" fn(
KeyedEventHandle: *mut HANDLE,
DesiredAccess: u32,
ObjectAttributes: *mut ffi::c_void,
Flags: u32,
) -> NTSTATUS = unsafe { mem::transmute(NtCreateKeyedEvent) };
let mut handle = MaybeUninit::uninit();
let status = NtCreateKeyedEvent(
handle.as_mut_ptr(),
GENERIC_READ | GENERIC_WRITE,
ptr::null_mut(),
0,
);
if status != STATUS_SUCCESS {
return None;
}
let NtCreateKeyedEvent =
unsafe { GetProcAddress(ntdll, b"NtCreateKeyedEvent\0".as_ptr())? };
let NtReleaseKeyedEvent =
unsafe { GetProcAddress(ntdll, b"NtReleaseKeyedEvent\0".as_ptr())? };
let NtWaitForKeyedEvent =
unsafe { GetProcAddress(ntdll, b"NtWaitForKeyedEvent\0".as_ptr())? };

let NtCreateKeyedEvent: extern "system" fn(
KeyedEventHandle: *mut HANDLE,
DesiredAccess: u32,
ObjectAttributes: *mut ffi::c_void,
Flags: u32,
) -> NTSTATUS = unsafe { mem::transmute(NtCreateKeyedEvent) };
let mut handle = MaybeUninit::uninit();
let status = NtCreateKeyedEvent(
handle.as_mut_ptr(),
GENERIC_READ | GENERIC_WRITE,
ptr::null_mut(),
0,
);
if status != STATUS_SUCCESS {
return None;
}

Some(KeyedEvent {
handle: unsafe { handle.assume_init() },
NtReleaseKeyedEvent: unsafe { mem::transmute(NtReleaseKeyedEvent) },
NtWaitForKeyedEvent: unsafe { mem::transmute(NtWaitForKeyedEvent) },
})
Some(KeyedEvent {
handle: unsafe { handle.assume_init() },
NtReleaseKeyedEvent: unsafe { mem::transmute(NtReleaseKeyedEvent) },
NtWaitForKeyedEvent: unsafe { mem::transmute(NtWaitForKeyedEvent) },
})
}

#[inline]
Expand Down
27 changes: 13 additions & 14 deletions core/src/thread_parker/windows/waitaddress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,21 @@ pub struct WaitAddress {
impl WaitAddress {
#[allow(non_snake_case)]
pub fn create() -> Option<WaitAddress> {
// MSDN claims that that WaitOnAddress and WakeByAddressSingle are
// located in kernel32.dll, but they are lying...
let synch_dll =
unsafe { GetModuleHandleA(b"api-ms-win-core-synch-l1-2-0.dll\0".as_ptr()) };
if synch_dll == 0 {
return None;
}
// MSDN claims that that WaitOnAddress and WakeByAddressSingle are
// located in kernel32.dll, but they are lying...
let synch_dll = unsafe { GetModuleHandleA(b"api-ms-win-core-synch-l1-2-0.dll\0".as_ptr()) };
if synch_dll == 0 {
return None;
}

let WaitOnAddress = unsafe { GetProcAddress(synch_dll, b"WaitOnAddress\0".as_ptr())? };
let WakeByAddressSingle =
unsafe { GetProcAddress(synch_dll, b"WakeByAddressSingle\0".as_ptr())? };
let WaitOnAddress = unsafe { GetProcAddress(synch_dll, b"WaitOnAddress\0".as_ptr())? };
let WakeByAddressSingle =
unsafe { GetProcAddress(synch_dll, b"WakeByAddressSingle\0".as_ptr())? };

Some(WaitAddress {
WaitOnAddress: unsafe { mem::transmute(WaitOnAddress) },
WakeByAddressSingle: unsafe { mem::transmute(WakeByAddressSingle) },
})
Some(WaitAddress {
WaitOnAddress: unsafe { mem::transmute(WaitOnAddress) },
WakeByAddressSingle: unsafe { mem::transmute(WakeByAddressSingle) },
})
}

#[inline]
Expand Down
Loading

0 comments on commit 584a916

Please sign in to comment.