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