about summary refs log tree commit diff
path: root/compiler/rustc_data_structures/src/sync
diff options
context:
space:
mode:
authorJohn Kåre Alsaker <john.kare.alsaker@gmail.com>2023-09-02 01:22:22 +0200
committerJohn Kåre Alsaker <john.kare.alsaker@gmail.com>2023-09-02 08:13:07 +0200
commit50f0d666d3308f0b0a45842cbe725fcb5b3c3861 (patch)
treef40087a8cb106930350af3a62de6c6ce7d8e2c13 /compiler/rustc_data_structures/src/sync
parent25884ec9be2115c729ac114fd6c62e4037584b08 (diff)
downloadrust-50f0d666d3308f0b0a45842cbe725fcb5b3c3861.tar.gz
rust-50f0d666d3308f0b0a45842cbe725fcb5b3c3861.zip
Add some comments
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);
         }