Skip to content

Commit af575cf

Browse files
committed
TryAcquireSRWLock workaround
1 parent f916031 commit af575cf

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

library/std/src/sys/pal/windows/c.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ mod windows_sys;
1212
pub use windows_sys::*;
1313

1414
pub type WCHAR = u16;
15+
pub type BOOLEAN = i32;
16+
pub const TRUE: BOOLEAN = 1;
17+
pub const FALSE: BOOLEAN = 0;
1518

1619
pub const INVALID_HANDLE_VALUE: HANDLE = ::core::ptr::without_provenance_mut(-1i32 as _);
1720

@@ -106,6 +109,17 @@ if #[cfg(not(target_vendor = "uwp"))] {
106109
}
107110
}
108111

112+
pub unsafe fn TryAcquireSRWLockExclusive(srwlock: *mut SRWLOCK) -> BOOLEAN {
113+
unsafe {AcquireSRWLockExclusive(srwlock)};
114+
TRUE // Always return TRUE for blocking lock
115+
}
116+
117+
#[allow(dead_code)]
118+
pub unsafe fn TryAcquireSRWLockShared(srwlock: *mut SRWLOCK) -> BOOLEAN {
119+
unsafe {AcquireSRWLockShared(srwlock)};
120+
TRUE // Always return TRUE for blocking lock
121+
}
122+
109123
// Use raw-dylib to import ProcessPrng as we can't rely on there being an import library.
110124
// Functions that aren't available on every version of Windows that we support,
111125
// but we still use them and just provide some form of a fallback implementation.

library/std/src/sys/pal/windows/c/windows_sys.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,6 @@ windows_targets::link!("kernel32.dll" "system" fn TlsAlloc() -> u32);
9696
windows_targets::link!("kernel32.dll" "system" fn TlsFree(dwtlsindex : u32) -> BOOL);
9797
windows_targets::link!("kernel32.dll" "system" fn TlsGetValue(dwtlsindex : u32) -> *mut core::ffi::c_void);
9898
windows_targets::link!("kernel32.dll" "system" fn TlsSetValue(dwtlsindex : u32, lptlsvalue : *const core::ffi::c_void) -> BOOL);
99-
windows_targets::link!("kernel32.dll" "system" fn TryAcquireSRWLockExclusive(srwlock : *mut SRWLOCK) -> BOOLEAN);
100-
windows_targets::link!("kernel32.dll" "system" fn TryAcquireSRWLockShared(srwlock : *mut SRWLOCK) -> BOOLEAN);
10199
windows_targets::link!("kernel32.dll" "system" fn UnlockFile(hfile : HANDLE, dwfileoffsetlow : u32, dwfileoffsethigh : u32, nnumberofbytestounlocklow : u32, nnumberofbytestounlockhigh : u32) -> BOOL);
102100
windows_targets::link!("kernel32.dll" "system" fn UpdateProcThreadAttribute(lpattributelist : LPPROC_THREAD_ATTRIBUTE_LIST, dwflags : u32, attribute : usize, lpvalue : *const core::ffi::c_void, cbsize : usize, lppreviousvalue : *mut core::ffi::c_void, lpreturnsize : *const usize) -> BOOL);
103101
windows_targets::link!("kernel32.dll" "system" fn WaitForMultipleObjects(ncount : u32, lphandles : *const HANDLE, bwaitall : BOOL, dwmilliseconds : u32) -> WAIT_EVENT);

0 commit comments

Comments
 (0)