File tree Expand file tree Collapse file tree 1 file changed +8
-14
lines changed
library/std/src/sys/unsupported Expand file tree Collapse file tree 1 file changed +8
-14
lines changed Original file line number Diff line number Diff line change 1
- use crate :: cell:: UnsafeCell ;
1
+ #![ deny( unsafe_op_in_unsafe_fn) ]
2
+
3
+ use crate :: cell:: Cell ;
2
4
3
5
pub struct Mutex {
4
- locked : UnsafeCell < bool > ,
6
+ locked : Cell < bool > ,
5
7
}
6
8
7
9
pub type MovableMutex = Mutex ;
@@ -12,33 +14,25 @@ unsafe impl Sync for Mutex {} // no threads on this platform
12
14
impl Mutex {
13
15
#[ rustc_const_stable( feature = "const_sys_mutex_new" , since = "1.0.0" ) ]
14
16
pub const fn new ( ) -> Mutex {
15
- Mutex { locked : UnsafeCell :: new ( false ) }
17
+ Mutex { locked : Cell :: new ( false ) }
16
18
}
17
19
18
20
#[ inline]
19
21
pub unsafe fn init ( & mut self ) { }
20
22
21
23
#[ inline]
22
24
pub unsafe fn lock ( & self ) {
23
- let locked = self . locked . get ( ) ;
24
- assert ! ( !* locked, "cannot recursively acquire mutex" ) ;
25
- * locked = true ;
25
+ assert_eq ! ( self . locked. replace( true ) , false , "cannot recursively acquire mutex" ) ;
26
26
}
27
27
28
28
#[ inline]
29
29
pub unsafe fn unlock ( & self ) {
30
- * self . locked . get ( ) = false ;
30
+ self . locked . set ( false ) ;
31
31
}
32
32
33
33
#[ inline]
34
34
pub unsafe fn try_lock ( & self ) -> bool {
35
- let locked = self . locked . get ( ) ;
36
- if * locked {
37
- false
38
- } else {
39
- * locked = true ;
40
- true
41
- }
35
+ self . locked . replace ( true ) == false
42
36
}
43
37
44
38
#[ inline]
You can’t perform that action at this time.
0 commit comments