File tree Expand file tree Collapse file tree 1 file changed +4
-1
lines changed
compiler/rustc_data_structures/src/sync Expand file tree Collapse file tree 1 file changed +4
-1
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,8 @@ use std::{
99
1010/// A type which allows mutation using a lock until
1111/// the value is frozen and can be accessed lock-free.
12+ ///
13+ /// Unlike `RwLock`, it can be used to prevent mutation past a point.
1214#[ derive( Default ) ]
1315pub struct Freeze < T > {
1416 data : UnsafeCell < T > ,
@@ -46,6 +48,7 @@ impl<T> Freeze<T> {
4648 #[ track_caller]
4749 pub fn write ( & self ) -> FreezeWriteGuard < ' _ , T > {
4850 let _lock_guard = self . lock . write ( ) ;
51+ // Use relaxed ordering since we're in the write lock.
4952 assert ! ( !self . frozen. load( Ordering :: Relaxed ) , "still mutable" ) ;
5053 FreezeWriteGuard {
5154 _lock_guard,
@@ -58,7 +61,7 @@ impl<T> Freeze<T> {
5861 #[ inline]
5962 pub fn freeze ( & self ) -> & T {
6063 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 .
6265 let _lock = self . lock . write ( ) ;
6366 self . frozen . store ( true , Ordering :: Release ) ;
6467 }
You can’t perform that action at this time.
0 commit comments