@@ -23,7 +23,8 @@ impl RWLock {
2323 /// previous method call.
2424 #[ inline]
2525 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 ( ) }
2728 }
2829
2930 /// Attempts to acquire shared access to this lock, returning whether it
@@ -35,7 +36,8 @@ impl RWLock {
3536 /// previous method call.
3637 #[ inline]
3738 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 ( ) }
3941 }
4042
4143 /// Acquires write access to the underlying lock, blocking the current thread
@@ -45,7 +47,8 @@ impl RWLock {
4547 /// previous method call.
4648 #[ inline]
4749 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 ( ) }
4952 }
5053
5154 /// Attempts to acquire exclusive access to this lock, returning whether it
@@ -57,15 +60,17 @@ impl RWLock {
5760 /// previous method call.
5861 #[ inline]
5962 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 ( ) }
6165 }
6266
6367 /// Unlocks previously acquired shared access to this lock.
6468 ///
6569 /// Behavior is undefined if the current thread does not have shared access.
6670 #[ inline]
6771 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 ( ) }
6974 }
7075
7176 /// Unlocks previously acquired exclusive access to this lock.
@@ -74,7 +79,8 @@ impl RWLock {
7479 /// exclusive access.
7580 #[ inline]
7681 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 ( ) }
7884 }
7985
8086 /// Destroys OS-related resources with this RWLock.
@@ -83,6 +89,7 @@ impl RWLock {
8389 /// lock.
8490 #[ inline]
8591 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 ( ) }
8794 }
8895}
0 commit comments