File tree Expand file tree Collapse file tree
library/std/src/sys/sync/rwlock Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -17,12 +17,8 @@ impl RwLock {
1717 #[ inline]
1818 pub fn read ( & self ) {
1919 let m = self . mode . get ( ) ;
20-
21- // Check for overflow.
22- assert ! ( m == isize :: MAX , "too many active read locks on RwLock" ) ;
23-
2420 if m >= 0 {
25- self . mode . set ( m + 1 ) ;
21+ self . mode . set ( m. checked_add ( 1 ) . expect ( "rwlock overflowed read locks" ) ) ;
2622 } else {
2723 rtabort ! ( "rwlock locked for writing" ) ;
2824 }
@@ -63,16 +59,19 @@ impl RwLock {
6359
6460 #[ inline]
6561 pub unsafe fn read_unlock ( & self ) {
66- self . mode . set ( self . mode . get ( ) - 1 ) ;
62+ assert ! (
63+ self . mode. replace( self . mode. get( ) - 1 ) > 0 ,
64+ "rwlock has not been locked for reading"
65+ ) ;
6766 }
6867
6968 #[ inline]
7069 pub unsafe fn write_unlock ( & self ) {
71- assert_eq ! ( self . mode. replace( 0 ) , -1 ) ;
70+ assert_eq ! ( self . mode. replace( 0 ) , -1 , "rwlock has not been locked for writing" ) ;
7271 }
7372
7473 #[ inline]
7574 pub unsafe fn downgrade ( & self ) {
76- assert_eq ! ( self . mode. replace( 1 ) , -1 ) ;
75+ assert_eq ! ( self . mode. replace( 1 ) , -1 , "rwlock has not been locked for writing" ) ;
7776 }
7877}
You can’t perform that action at this time.
0 commit comments