File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed 
library/std/src/sys/unix/locks Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change 11use  crate :: cell:: UnsafeCell ; 
2+ use  crate :: mem:: forget; 
23use  crate :: sync:: atomic:: { AtomicUsize ,  Ordering } ; 
34use  crate :: sys_common:: lazy_box:: { LazyBox ,  LazyInit } ; 
45
@@ -17,6 +18,21 @@ impl LazyInit for RwLock {
1718    fn  init ( )  -> Box < Self >  { 
1819        Box :: new ( Self :: new ( ) ) 
1920    } 
21+ 
22+     fn  destroy ( mut  rwlock :  Box < Self > )  { 
23+         // We're not allowed to pthread_rwlock_destroy a locked rwlock, 
24+         // so check first if it's unlocked. 
25+         if  * rwlock. write_locked . get_mut ( )  || * rwlock. num_readers . get_mut ( )  != 0  { 
26+             // The rwlock is locked. This happens if a RwLock{Read,Write}Guard is leaked. 
27+             // In this case, we just leak the RwLock too. 
28+             forget ( rwlock) ; 
29+         } 
30+     } 
31+ 
32+     fn  cancel_init ( _:  Box < Self > )  { 
33+         // In this case, we can just drop it without any checks, 
34+         // since it cannot have been locked yet. 
35+     } 
2036} 
2137
2238impl  RwLock  { 
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments