1 use crate::sys::rwlock as imp;
3 /// An OS-based reader-writer lock.
5 /// This structure is entirely unsafe and serves as the lowest layer of a
6 /// cross-platform binding of system rwlocks. It is recommended to use the
7 /// safer types at the top level of this crate instead of this type.
8 pub struct RWLock(imp::RWLock);
11 /// Creates a new reader-writer lock for use.
13 /// Behavior is undefined if the reader-writer lock is moved after it is
14 /// first used with any of the functions below.
15 pub const fn new() -> RWLock {
16 RWLock(imp::RWLock::new())
19 /// Acquires shared access to the underlying lock, blocking the current
22 /// Behavior is undefined if the rwlock has been moved between this and any
23 /// previous method call.
25 pub unsafe fn read(&self) {
29 /// Attempts to acquire shared access to this lock, returning whether it
32 /// This function does not block the current thread.
34 /// Behavior is undefined if the rwlock has been moved between this and any
35 /// previous method call.
37 pub unsafe fn try_read(&self) -> bool {
41 /// Acquires write access to the underlying lock, blocking the current thread
44 /// Behavior is undefined if the rwlock has been moved between this and any
45 /// previous method call.
47 pub unsafe fn write(&self) {
51 /// Attempts to acquire exclusive access to this lock, returning whether it
54 /// This function does not block the current thread.
56 /// Behavior is undefined if the rwlock has been moved between this and any
57 /// previous method call.
59 pub unsafe fn try_write(&self) -> bool {
63 /// Unlocks previously acquired shared access to this lock.
65 /// Behavior is undefined if the current thread does not have shared access.
67 pub unsafe fn read_unlock(&self) {
71 /// Unlocks previously acquired exclusive access to this lock.
73 /// Behavior is undefined if the current thread does not currently have
76 pub unsafe fn write_unlock(&self) {
80 /// Destroys OS-related resources with this RWLock.
82 /// Behavior is undefined if there are any currently active users of this
85 pub unsafe fn destroy(&self) {