1+ #![ deny( unsafe_op_in_unsafe_fn) ]
2+
13use crate :: ffi:: c_void;
24use crate :: ptr;
35use crate :: sync:: atomic:: { AtomicUsize , Ordering :: SeqCst } ;
@@ -23,33 +25,43 @@ impl Condvar {
2325 }
2426
2527 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+ }
2832 }
2933
3034 pub unsafe fn notify_one ( & self ) {
3135 if self . counter . load ( SeqCst ) > 0 {
3236 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+ }
3541 }
3642 }
3743
3844 pub unsafe fn notify_all ( & self ) {
3945 let counter = self . counter . swap ( 0 , SeqCst ) ;
4046 for _ in 0 ..counter {
41- abi:: sem_post ( self . sem1 ) ;
47+ unsafe {
48+ abi:: sem_post ( self . sem1 ) ;
49+ }
4250 }
4351 for _ in 0 ..counter {
44- abi:: sem_timedwait ( self . sem2 , 0 ) ;
52+ unsafe {
53+ abi:: sem_timedwait ( self . sem2 , 0 ) ;
54+ }
4555 }
4656 }
4757
4858 pub unsafe fn wait ( & self , mutex : & Mutex ) {
4959 self . counter . fetch_add ( 1 , SeqCst ) ;
5060 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+ }
5365 mutex. lock ( ) ;
5466 }
5567
@@ -58,7 +70,9 @@ impl Condvar {
5870 }
5971
6072 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+ }
6377 }
6478}
0 commit comments