Debian Codegraph @

third_party/rust/windows-core/src/imp/waiter.rs

raw
1 use super::*;
2
3 pub struct Waiter(HANDLE);
4 pub struct WaiterSignaler(HANDLE);
5
6 unsafe impl Send for WaiterSignaler {}
7
8 impl Waiter {
9 pub fn new() -> crate::Result<(Waiter, WaiterSignaler)> {
10 unsafe {
11 let handle = CreateEventW(core::ptr::null(), 1, 0, core::ptr::null());
12 if handle.is_null() {
13 Err(crate::Error::from_win32())
14 } else {
15 Ok((Waiter(handle), WaiterSignaler(handle)))
16 }
17 }
18 }
19 }
20
21 impl WaiterSignaler {
22 /// # Safety
23 /// Signals the `Waiter`. This is unsafe because the lifetime of `WaiterSignaler` is not tied
24 /// to the lifetime of the `Waiter`. This is not possible in this case because the `Waiter`
25 /// is used to signal a WinRT async completion and the compiler doesn't know that the lifetime
26 /// of the delegate is bounded by the calling function.
27 pub unsafe fn signal(&self) {
28 // https://github.com/microsoft/windows-rs/pull/374#discussion_r535313344
29 SetEvent(self.0);
30 }
31 }
32
33 impl Drop for Waiter {
34 fn drop(&mut self) {
35 unsafe {
36 WaitForSingleObject(self.0, 0xFFFFFFFF);
37 CloseHandle(self.0);
38 }
39 }
40 }