about summary refs log tree commit diff
path: root/compiler/rustc_data_structures/src/sync
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_data_structures/src/sync')
-rw-r--r--compiler/rustc_data_structures/src/sync/freeze.rs5
1 files changed, 4 insertions, 1 deletions
diff --git a/compiler/rustc_data_structures/src/sync/freeze.rs b/compiler/rustc_data_structures/src/sync/freeze.rs
index 21bbc35e317..e9ad6ee8394 100644
--- a/compiler/rustc_data_structures/src/sync/freeze.rs
+++ b/compiler/rustc_data_structures/src/sync/freeze.rs
@@ -9,6 +9,8 @@ use std::{
 
 /// A type which allows mutation using a lock until
 /// the value is frozen and can be accessed lock-free.
+///
+/// Unlike `RwLock`, it can be used to prevent mutation past a point.
 #[derive(Default)]
 pub struct Freeze<T> {
     data: UnsafeCell<T>,
@@ -46,6 +48,7 @@ impl<T> Freeze<T> {
     #[track_caller]
     pub fn write(&self) -> FreezeWriteGuard<'_, T> {
         let _lock_guard = self.lock.write();
+        // Use relaxed ordering since we're in the write lock.
         assert!(!self.frozen.load(Ordering::Relaxed), "still mutable");
         FreezeWriteGuard {
             _lock_guard,
@@ -58,7 +61,7 @@ impl<T> Freeze<T> {
     #[inline]
     pub fn freeze(&self) -> &T {
         if !self.frozen.load(Ordering::Acquire) {
-            // Get the lock to ensure no concurrent writes.
+            // Get the lock to ensure no concurrent writes and that we release the latest write.
             let _lock = self.lock.write();
             self.frozen.store(true, Ordering::Release);
         }