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.
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.
16 pub struct RWLock { inner: UnsafeCell<ffi::SRWLOCK> }
18 unsafe impl Send
for RWLock {}
19 unsafe impl Sync
for RWLock {}
22 pub const fn new() -> RWLock
{
23 RWLock { inner: UnsafeCell::new(ffi::SRWLOCK_INIT) }
26 pub unsafe fn read(&self) {
27 ffi
::AcquireSRWLockShared(self.inner
.get())
30 pub unsafe fn try_read(&self) -> bool
{
31 ffi
::TryAcquireSRWLockShared(self.inner
.get()) != 0
34 pub unsafe fn write(&self) {
35 ffi
::AcquireSRWLockExclusive(self.inner
.get())
38 pub unsafe fn try_write(&self) -> bool
{
39 ffi
::TryAcquireSRWLockExclusive(self.inner
.get()) != 0
42 pub unsafe fn read_unlock(&self) {
43 ffi
::ReleaseSRWLockShared(self.inner
.get())
46 pub unsafe fn write_unlock(&self) {
47 ffi
::ReleaseSRWLockExclusive(self.inner
.get())
51 pub unsafe fn destroy(&self) {