File tree 1 file changed +4
-1
lines changed
compiler/rustc_data_structures/src/sync
1 file changed +4
-1
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,8 @@ use std::{
9
9
10
10
/// A type which allows mutation using a lock until
11
11
/// the value is frozen and can be accessed lock-free.
12
+ ///
13
+ /// Unlike `RwLock`, it can be used to prevent mutation past a point.
12
14
#[ derive( Default ) ]
13
15
pub struct Freeze < T > {
14
16
data : UnsafeCell < T > ,
@@ -46,6 +48,7 @@ impl<T> Freeze<T> {
46
48
#[ track_caller]
47
49
pub fn write ( & self ) -> FreezeWriteGuard < ' _ , T > {
48
50
let _lock_guard = self . lock . write ( ) ;
51
+ // Use relaxed ordering since we're in the write lock.
49
52
assert ! ( !self . frozen. load( Ordering :: Relaxed ) , "still mutable" ) ;
50
53
FreezeWriteGuard {
51
54
_lock_guard,
@@ -58,7 +61,7 @@ impl<T> Freeze<T> {
58
61
#[ inline]
59
62
pub fn freeze ( & self ) -> & T {
60
63
if !self . frozen . load ( Ordering :: Acquire ) {
61
- // Get the lock to ensure no concurrent writes.
64
+ // Get the lock to ensure no concurrent writes and that we release the latest write .
62
65
let _lock = self . lock . write ( ) ;
63
66
self . frozen . store ( true , Ordering :: Release ) ;
64
67
}
You can’t perform that action at this time.
0 commit comments