]> git.proxmox.com Git - rustc.git/blob - src/libstd/sys/windows/rwlock.rs
e727638e3e9b5cddf67a2dfd14792649627a1080
[rustc.git] / src / libstd / sys / windows / rwlock.rs
1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 use prelude::v1::*;
12
13 use cell::UnsafeCell;
14 use sys::sync as ffi;
15
16 pub struct RWLock { inner: UnsafeCell<ffi::SRWLOCK> }
17
18 unsafe impl Send for RWLock {}
19 unsafe impl Sync for RWLock {}
20
21 impl RWLock {
22 pub const fn new() -> RWLock {
23 RWLock { inner: UnsafeCell::new(ffi::SRWLOCK_INIT) }
24 }
25 #[inline]
26 pub unsafe fn read(&self) {
27 ffi::AcquireSRWLockShared(self.inner.get())
28 }
29 #[inline]
30 pub unsafe fn try_read(&self) -> bool {
31 ffi::TryAcquireSRWLockShared(self.inner.get()) != 0
32 }
33 #[inline]
34 pub unsafe fn write(&self) {
35 ffi::AcquireSRWLockExclusive(self.inner.get())
36 }
37 #[inline]
38 pub unsafe fn try_write(&self) -> bool {
39 ffi::TryAcquireSRWLockExclusive(self.inner.get()) != 0
40 }
41 #[inline]
42 pub unsafe fn read_unlock(&self) {
43 ffi::ReleaseSRWLockShared(self.inner.get())
44 }
45 #[inline]
46 pub unsafe fn write_unlock(&self) {
47 ffi::ReleaseSRWLockExclusive(self.inner.get())
48 }
49
50 #[inline]
51 pub unsafe fn destroy(&self) {
52 // ...
53 }
54 }