Skip to content

Commit 8abafd0

Browse files
committed
Add some comments
1 parent 5843858 commit 8abafd0

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

compiler/rustc_data_structures/src/sharded.rs

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ pub const SHARDS: usize = 1 << SHARD_BITS;
2020

2121
/// An array of cache-line aligned inner locked structures with convenience methods.
2222
pub struct Sharded<T> {
23+
/// This mask is used to ensure that accesses are inbounds of `shards`.
24+
/// When dynamic thread safety is off, this field is set to 0 causing only
25+
/// a single shard to be used for greater cache efficiency.
2326
#[cfg(parallel_compiler)]
2427
mask: usize,
2528
shards: [CacheAligned<Lock<T>>; SHARDS],
@@ -56,6 +59,7 @@ impl<T> Sharded<T> {
5659

5760
#[inline(always)]
5861
fn count(&self) -> usize {
62+
// `self.mask` is always one below the used shard count
5963
self.mask() + 1
6064
}
6165

0 commit comments

Comments
 (0)