Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion benchmark/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ nightly = ["parking_lot/nightly"]
deadlock_detection = ["parking_lot/deadlock_detection"]

[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3", features = ["synchapi"] }
windows-sys = { version = "0.60", features = ["Win32_System_Threading"] }
16 changes: 9 additions & 7 deletions benchmark/src/bin/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,24 @@ impl<T> Mutex<T> for parking_lot::Mutex<T> {
type SrwLock<T> = std::sync::Mutex<T>;

#[cfg(windows)]
use winapi::um::synchapi;
use windows_sys::Win32::System::Threading::{
SRWLOCK, InitializeSRWLock, AcquireSRWLockExclusive, ReleaseSRWLockExclusive,
};
#[cfg(windows)]
struct SrwLock<T>(UnsafeCell<T>, UnsafeCell<synchapi::SRWLOCK>);
struct SrwLock<T>(UnsafeCell<T>, UnsafeCell<SRWLOCK>);
#[cfg(windows)]
unsafe impl<T> Sync for SrwLock<T> {}
#[cfg(windows)]
unsafe impl<T: Send> Send for SrwLock<T> {}
#[cfg(windows)]
impl<T> Mutex<T> for SrwLock<T> {
fn new(v: T) -> Self {
let mut h: synchapi::SRWLOCK = synchapi::SRWLOCK {
let mut h: SRWLOCK = SRWLOCK {
Ptr: std::ptr::null_mut(),
};

unsafe {
synchapi::InitializeSRWLock(&mut h);
InitializeSRWLock(&mut h);
}
SrwLock(UnsafeCell::new(v), UnsafeCell::new(h))
}
Expand All @@ -85,14 +87,14 @@ impl<T> Mutex<T> for SrwLock<T> {
F: FnOnce(&mut T) -> R,
{
unsafe {
synchapi::AcquireSRWLockExclusive(self.1.get());
AcquireSRWLockExclusive(self.1.get());
let res = f(&mut *self.0.get());
synchapi::ReleaseSRWLockExclusive(self.1.get());
ReleaseSRWLockExclusive(self.1.get());
res
}
}
fn name() -> &'static str {
"winapi_srwlock"
"windows_sys_srwlock"
}
}

Expand Down
21 changes: 12 additions & 9 deletions benchmark/src/bin/rwlock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,22 +97,25 @@ impl<T: Copy> RwLock<T> for seqlock::SeqLock<T> {
type SrwLock<T> = std::sync::RwLock<T>;

#[cfg(windows)]
use winapi::um::synchapi;
use windows_sys::Win32::System::Threading::{
SRWLOCK, InitializeSRWLock, AcquireSRWLockExclusive, ReleaseSRWLockExclusive,
AcquireSRWLockShared, ReleaseSRWLockShared,
};
#[cfg(windows)]
struct SrwLock<T>(UnsafeCell<T>, UnsafeCell<synchapi::SRWLOCK>);
struct SrwLock<T>(UnsafeCell<T>, UnsafeCell<SRWLOCK>);
#[cfg(windows)]
unsafe impl<T> Sync for SrwLock<T> {}
#[cfg(windows)]
unsafe impl<T: Send> Send for SrwLock<T> {}
#[cfg(windows)]
impl<T> RwLock<T> for SrwLock<T> {
fn new(v: T) -> Self {
let mut h: synchapi::SRWLOCK = synchapi::SRWLOCK {
let mut h: SRWLOCK = SRWLOCK {
Ptr: std::ptr::null_mut(),
};

unsafe {
synchapi::InitializeSRWLock(&mut h);
InitializeSRWLock(&mut h);
}
SrwLock(UnsafeCell::new(v), UnsafeCell::new(h))
}
Expand All @@ -121,9 +124,9 @@ impl<T> RwLock<T> for SrwLock<T> {
F: FnOnce(&T) -> R,
{
unsafe {
synchapi::AcquireSRWLockShared(self.1.get());
AcquireSRWLockShared(self.1.get());
let res = f(&*self.0.get());
synchapi::ReleaseSRWLockShared(self.1.get());
ReleaseSRWLockShared(self.1.get());
res
}
}
Expand All @@ -132,14 +135,14 @@ impl<T> RwLock<T> for SrwLock<T> {
F: FnOnce(&mut T) -> R,
{
unsafe {
synchapi::AcquireSRWLockExclusive(self.1.get());
AcquireSRWLockExclusive(self.1.get());
let res = f(&mut *self.0.get());
synchapi::ReleaseSRWLockExclusive(self.1.get());
ReleaseSRWLockExclusive(self.1.get());
res
}
}
fn name() -> &'static str {
"winapi_srwlock"
"windows_sys_srwlock"
}
}

Expand Down
Loading