1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
mod imp {
use super::super::*;
pub struct Waiter(HANDLE);
pub struct WaiterSignaler(HANDLE);
unsafe impl Send for WaiterSignaler {}
impl Waiter {
pub fn new() -> Result<(Self, WaiterSignaler)> {
unsafe {
let handle = CreateEventW(core::ptr::null(), 1, 0, core::ptr::null());
if handle.is_null() {
Err(Error::from_thread())
} else {
Ok((Self(handle), WaiterSignaler(handle)))
}
}
}
// Waits for the `WaiterSignaler` to signal and then closes the handle.
pub fn wait(self) {
unsafe {
WaitForSingleObject(self.0, 0xFFFFFFFF);
}
}
}
impl WaiterSignaler {
/// # Safety
///
/// The associated `Waiter` must not have been dropped.
pub unsafe fn signal(&self) {
// https://github.com/microsoft/windows-rs/pull/374#discussion_r535313344
unsafe {
SetEvent(self.0);
}
}
}
impl Drop for Waiter {
fn drop(&mut self) {
unsafe {
CloseHandle(self.0);
}
}
}
}
pub use imp::*;