1
+ use crate :: marker:: PhantomPinned ;
1
2
use crate :: pin:: Pin ;
2
3
use crate :: sys:: rwlock as imp;
3
4
@@ -6,22 +7,25 @@ use crate::sys::rwlock as imp;
6
7
/// This structure is entirely unsafe and serves as the lowest layer of a
7
8
/// cross-platform binding of system rwlocks. It is recommended to use the
8
9
/// safer types at the top level of this crate instead of this type.
9
- pub struct RWLock ( imp:: RWLock ) ;
10
+ pub struct RWLock {
11
+ inner : imp:: RWLock ,
12
+ _pinned : PhantomPinned ,
13
+ }
10
14
11
15
impl RWLock {
12
16
/// Creates a new reader-writer lock for use.
13
17
///
14
18
/// Behavior is undefined if the reader-writer lock is moved after it is
15
19
/// first used with any of the functions below.
16
20
pub const fn new ( ) -> RWLock {
17
- RWLock ( imp:: RWLock :: new ( ) )
21
+ RWLock { inner : imp:: RWLock :: new ( ) , _pinned : PhantomPinned }
18
22
}
19
23
20
24
/// Acquires shared access to the underlying lock, blocking the current
21
25
/// thread to do so.
22
26
#[ inline]
23
27
pub fn read ( self : Pin < & Self > ) {
24
- unsafe { self . 0 . read ( ) }
28
+ unsafe { self . inner . read ( ) }
25
29
}
26
30
27
31
/// Attempts to acquire shared access to this lock, returning whether it
@@ -30,14 +34,14 @@ impl RWLock {
30
34
/// This function does not block the current thread.
31
35
#[ inline]
32
36
pub fn try_read ( self : Pin < & Self > ) -> bool {
33
- unsafe { self . 0 . try_read ( ) }
37
+ unsafe { self . inner . try_read ( ) }
34
38
}
35
39
36
40
/// Acquires write access to the underlying lock, blocking the current thread
37
41
/// to do so.
38
42
#[ inline]
39
43
pub fn write ( self : Pin < & Self > ) {
40
- unsafe { self . 0 . write ( ) }
44
+ unsafe { self . inner . write ( ) }
41
45
}
42
46
43
47
/// Attempts to acquire exclusive access to this lock, returning whether it
@@ -46,15 +50,15 @@ impl RWLock {
46
50
/// This function does not block the current thread.
47
51
#[ inline]
48
52
pub fn try_write ( self : Pin < & Self > ) -> bool {
49
- unsafe { self . 0 . try_write ( ) }
53
+ unsafe { self . inner . try_write ( ) }
50
54
}
51
55
52
56
/// Unlocks previously acquired shared access to this lock.
53
57
///
54
58
/// Behavior is undefined if the current thread does not have shared access.
55
59
#[ inline]
56
60
pub unsafe fn read_unlock ( self : Pin < & Self > ) {
57
- self . 0 . read_unlock ( )
61
+ self . inner . read_unlock ( )
58
62
}
59
63
60
64
/// Unlocks previously acquired exclusive access to this lock.
@@ -63,7 +67,7 @@ impl RWLock {
63
67
/// exclusive access.
64
68
#[ inline]
65
69
pub unsafe fn write_unlock ( self : Pin < & Self > ) {
66
- self . 0 . write_unlock ( )
70
+ self . inner . write_unlock ( )
67
71
}
68
72
}
69
73
@@ -72,6 +76,6 @@ impl Drop for RWLock {
72
76
fn drop ( & mut self ) {
73
77
// SAFETY: The rwlock wasn't moved since using any of its
74
78
// functions, because they all require a Pin.
75
- unsafe { self . 0 . destroy ( ) }
79
+ unsafe { self . inner . destroy ( ) }
76
80
}
77
81
}
0 commit comments