]> git.lizzy.rs Git - rust.git/blob - library/std/src/sys/windows/rwlock.rs
Auto merge of #82973 - ijackson:exitstatuserror, r=yaahc
[rust.git] / library / std / src / sys / windows / rwlock.rs
1 use crate::cell::UnsafeCell;
2 use crate::sys::c;
3
4 pub struct RWLock {
5     inner: UnsafeCell<c::SRWLOCK>,
6 }
7
8 unsafe impl Send for RWLock {}
9 unsafe impl Sync for RWLock {}
10
11 impl RWLock {
12     pub const fn new() -> RWLock {
13         RWLock { inner: UnsafeCell::new(c::SRWLOCK_INIT) }
14     }
15     #[inline]
16     pub unsafe fn read(&self) {
17         c::AcquireSRWLockShared(self.inner.get())
18     }
19     #[inline]
20     pub unsafe fn try_read(&self) -> bool {
21         c::TryAcquireSRWLockShared(self.inner.get()) != 0
22     }
23     #[inline]
24     pub unsafe fn write(&self) {
25         c::AcquireSRWLockExclusive(self.inner.get())
26     }
27     #[inline]
28     pub unsafe fn try_write(&self) -> bool {
29         c::TryAcquireSRWLockExclusive(self.inner.get()) != 0
30     }
31     #[inline]
32     pub unsafe fn read_unlock(&self) {
33         c::ReleaseSRWLockShared(self.inner.get())
34     }
35     #[inline]
36     pub unsafe fn write_unlock(&self) {
37         c::ReleaseSRWLockExclusive(self.inner.get())
38     }
39
40     #[inline]
41     pub unsafe fn destroy(&self) {
42         // ...
43     }
44 }