Add some comments
This commit is contained in:
parent
5843858c01
commit
8abafd085a
@ -20,6 +20,9 @@ pub const SHARDS: usize = 1 << SHARD_BITS;
|
|||||||
|
|
||||||
/// An array of cache-line aligned inner locked structures with convenience methods.
|
/// An array of cache-line aligned inner locked structures with convenience methods.
|
||||||
pub struct Sharded<T> {
|
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)]
|
#[cfg(parallel_compiler)]
|
||||||
mask: usize,
|
mask: usize,
|
||||||
shards: [CacheAligned<Lock<T>>; SHARDS],
|
shards: [CacheAligned<Lock<T>>; SHARDS],
|
||||||
@ -56,6 +59,7 @@ impl<T> Sharded<T> {
|
|||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn count(&self) -> usize {
|
fn count(&self) -> usize {
|
||||||
|
// `self.mask` is always one below the used shard count
|
||||||
self.mask() + 1
|
self.mask() + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user