]> git.proxmox.com Git - rustc.git/blob - vendor/fd-lock/src/sys/windows/read_guard.rs
Merge 1.70 into proxmox/bookworm
[rustc.git] / vendor / fd-lock / src / sys / windows / read_guard.rs
1 use windows_sys::Win32::Foundation::HANDLE;
2 use windows_sys::Win32::Storage::FileSystem::UnlockFile;
3
4 use std::ops;
5 use std::os::windows::prelude::*;
6
7 use super::utils::syscall;
8 use super::RwLock;
9
10 #[derive(Debug)]
11 pub struct RwLockReadGuard<'lock, T: AsRawHandle> {
12 pub(crate) lock: &'lock RwLock<T>,
13 }
14
15 impl<T: AsRawHandle> ops::Deref for RwLockReadGuard<'_, T> {
16 type Target = T;
17
18 #[inline]
19 fn deref(&self) -> &Self::Target {
20 &self.lock.inner
21 }
22 }
23
24 impl<T: AsRawHandle> Drop for RwLockReadGuard<'_, T> {
25 #[inline]
26 fn drop(&mut self) {
27 let handle = self.lock.inner.as_raw_handle() as HANDLE;
28 let _ = syscall(unsafe { UnlockFile(handle, 0, 0, 1, 0) });
29 }
30 }