File tree 1 file changed +16
-0
lines changed
library/std/src/sys/unix/locks
1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change 1
1
use crate :: cell:: UnsafeCell ;
2
+ use crate :: mem:: forget;
2
3
use crate :: sync:: atomic:: { AtomicUsize , Ordering } ;
3
4
use crate :: sys_common:: lazy_box:: { LazyBox , LazyInit } ;
4
5
@@ -17,6 +18,21 @@ impl LazyInit for RwLock {
17
18
fn init ( ) -> Box < Self > {
18
19
Box :: new ( Self :: new ( ) )
19
20
}
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
+ }
20
36
}
21
37
22
38
impl RwLock {
You can’t perform that action at this time.
0 commit comments