about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJohn Kåre Alsaker <john.kare.alsaker@gmail.com>2023-05-28 15:54:52 +0200
committerJohn Kåre Alsaker <john.kare.alsaker@gmail.com>2023-05-28 15:54:52 +0200
commit8abafd085aab9b703711b49d02b66910c8c2d739 (patch)
treed9e497e6a05d1d94668c14fa3693a685208ff486
parent5843858c015614c92515f317ce93796c885ca2cf (diff)
downloadrust-8abafd085aab9b703711b49d02b66910c8c2d739.tar.gz
rust-8abafd085aab9b703711b49d02b66910c8c2d739.zip
Add some comments
-rw-r--r--compiler/rustc_data_structures/src/sharded.rs4
1 files changed, 4 insertions, 0 deletions
diff --git a/compiler/rustc_data_structures/src/sharded.rs b/compiler/rustc_data_structures/src/sharded.rs
index 9f5c97ae798..40cbf14958e 100644
--- a/compiler/rustc_data_structures/src/sharded.rs
+++ b/compiler/rustc_data_structures/src/sharded.rs
@@ -20,6 +20,9 @@ pub const SHARDS: usize = 1 << SHARD_BITS;
 
 /// An array of cache-line aligned inner locked structures with convenience methods.
 pub struct Sharded<T> {
+    /// This mask is used to ensure that accesses are inbounds of `shards`.
+    /// When dynamic thread safety is off, this field is set to 0 causing only
+    /// a single shard to be used for greater cache efficiency.
     #[cfg(parallel_compiler)]
     mask: usize,
     shards: [CacheAligned<Lock<T>>; SHARDS],
@@ -56,6 +59,7 @@ impl<T> Sharded<T> {
 
     #[inline(always)]
     fn count(&self) -> usize {
+        // `self.mask` is always one below the used shard count
         self.mask() + 1
     }