@@ -23,7 +23,8 @@ impl RWLock {
23
23
/// previous method call.
24
24
#[ inline]
25
25
pub unsafe fn read ( & self ) {
26
- self . 0 . read ( )
26
+ // SAFETY: the caller must uphold the safety contract for `read`.
27
+ unsafe { self . 0 . read ( ) }
27
28
}
28
29
29
30
/// Attempts to acquire shared access to this lock, returning whether it
@@ -35,7 +36,8 @@ impl RWLock {
35
36
/// previous method call.
36
37
#[ inline]
37
38
pub unsafe fn try_read ( & self ) -> bool {
38
- self . 0 . try_read ( )
39
+ // SAFETY: the caller must uphold the safety contract for `try_read`.
40
+ unsafe { self . 0 . try_read ( ) }
39
41
}
40
42
41
43
/// Acquires write access to the underlying lock, blocking the current thread
@@ -45,7 +47,8 @@ impl RWLock {
45
47
/// previous method call.
46
48
#[ inline]
47
49
pub unsafe fn write ( & self ) {
48
- self . 0 . write ( )
50
+ // SAFETY: the caller must uphold the safety contract for `write`.
51
+ unsafe { self . 0 . write ( ) }
49
52
}
50
53
51
54
/// Attempts to acquire exclusive access to this lock, returning whether it
@@ -57,15 +60,17 @@ impl RWLock {
57
60
/// previous method call.
58
61
#[ inline]
59
62
pub unsafe fn try_write ( & self ) -> bool {
60
- self . 0 . try_write ( )
63
+ // SAFETY: the caller must uphold the safety contract for `try_write`.
64
+ unsafe { self . 0 . try_write ( ) }
61
65
}
62
66
63
67
/// Unlocks previously acquired shared access to this lock.
64
68
///
65
69
/// Behavior is undefined if the current thread does not have shared access.
66
70
#[ inline]
67
71
pub unsafe fn read_unlock ( & self ) {
68
- self . 0 . read_unlock ( )
72
+ // SAFETY: the caller must uphold the safety contract for `read_unlock`.
73
+ unsafe { self . 0 . read_unlock ( ) }
69
74
}
70
75
71
76
/// Unlocks previously acquired exclusive access to this lock.
@@ -74,7 +79,8 @@ impl RWLock {
74
79
/// exclusive access.
75
80
#[ inline]
76
81
pub unsafe fn write_unlock ( & self ) {
77
- self . 0 . write_unlock ( )
82
+ // SAFETY: the caller must uphold the safety contract for `write_unlock`.
83
+ unsafe { self . 0 . write_unlock ( ) }
78
84
}
79
85
80
86
/// Destroys OS-related resources with this RWLock.
@@ -83,6 +89,7 @@ impl RWLock {
83
89
/// lock.
84
90
#[ inline]
85
91
pub unsafe fn destroy ( & self ) {
86
- self . 0 . destroy ( )
92
+ // SAFETY: the caller must uphold the safety contract for `destroy`.
93
+ unsafe { self . 0 . destroy ( ) }
87
94
}
88
95
}
0 commit comments