Skip to content

Commit 50f0d66

Browse files
committed
Add some comments
1 parent 25884ec commit 50f0d66

File tree

1 file changed

+4
-1
lines changed
  • compiler/rustc_data_structures/src/sync

1 file changed

+4
-1
lines changed

compiler/rustc_data_structures/src/sync/freeze.rs

+4-1
Original file line numberDiff line numberDiff 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)]
1315
pub 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
}

0 commit comments

Comments
 (0)