1
+ #![ deny( unsafe_op_in_unsafe_fn) ]
2
+
1
3
use crate :: ffi:: c_void;
2
4
use crate :: ptr;
3
5
use crate :: sync:: atomic:: { AtomicUsize , Ordering :: SeqCst } ;
@@ -23,33 +25,43 @@ impl Condvar {
23
25
}
24
26
25
27
pub unsafe fn init ( & mut self ) {
26
- let _ = abi:: sem_init ( & mut self . sem1 as * mut * const c_void , 0 ) ;
27
- let _ = abi:: sem_init ( & mut self . sem2 as * mut * const c_void , 0 ) ;
28
+ unsafe {
29
+ let _ = abi:: sem_init ( & mut self . sem1 as * mut * const c_void , 0 ) ;
30
+ let _ = abi:: sem_init ( & mut self . sem2 as * mut * const c_void , 0 ) ;
31
+ }
28
32
}
29
33
30
34
pub unsafe fn notify_one ( & self ) {
31
35
if self . counter . load ( SeqCst ) > 0 {
32
36
self . counter . fetch_sub ( 1 , SeqCst ) ;
33
- abi:: sem_post ( self . sem1 ) ;
34
- abi:: sem_timedwait ( self . sem2 , 0 ) ;
37
+ unsafe {
38
+ abi:: sem_post ( self . sem1 ) ;
39
+ abi:: sem_timedwait ( self . sem2 , 0 ) ;
40
+ }
35
41
}
36
42
}
37
43
38
44
pub unsafe fn notify_all ( & self ) {
39
45
let counter = self . counter . swap ( 0 , SeqCst ) ;
40
46
for _ in 0 ..counter {
41
- abi:: sem_post ( self . sem1 ) ;
47
+ unsafe {
48
+ abi:: sem_post ( self . sem1 ) ;
49
+ }
42
50
}
43
51
for _ in 0 ..counter {
44
- abi:: sem_timedwait ( self . sem2 , 0 ) ;
52
+ unsafe {
53
+ abi:: sem_timedwait ( self . sem2 , 0 ) ;
54
+ }
45
55
}
46
56
}
47
57
48
58
pub unsafe fn wait ( & self , mutex : & Mutex ) {
49
59
self . counter . fetch_add ( 1 , SeqCst ) ;
50
60
mutex. unlock ( ) ;
51
- abi:: sem_timedwait ( self . sem1 , 0 ) ;
52
- abi:: sem_post ( self . sem2 ) ;
61
+ unsafe {
62
+ abi:: sem_timedwait ( self . sem1 , 0 ) ;
63
+ abi:: sem_post ( self . sem2 ) ;
64
+ }
53
65
mutex. lock ( ) ;
54
66
}
55
67
@@ -58,7 +70,9 @@ impl Condvar {
58
70
}
59
71
60
72
pub unsafe fn destroy ( & self ) {
61
- let _ = abi:: sem_destroy ( self . sem1 ) ;
62
- let _ = abi:: sem_destroy ( self . sem2 ) ;
73
+ unsafe {
74
+ let _ = abi:: sem_destroy ( self . sem1 ) ;
75
+ let _ = abi:: sem_destroy ( self . sem2 ) ;
76
+ }
63
77
}
64
78
}
0 commit comments