Skip to content

Commit

Permalink
Add some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoxc committed May 28, 2023
1 parent 5843858 commit 8abafd0
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions compiler/rustc_data_structures/src/sharded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 8abafd0

Please sign in to comment.