hawkw/sharded-slab

Why does TID require one extra bit?

loyd opened this issue · 2 comments

loyd commented

In tid.rs LEN is defined as:

const LEN: usize = C::MAX_SHARDS.trailing_zeros() as usize + 1;

that gives for the default config (MAX_THREADS = 4096) 13 bit space instead of 12:

    assert_eq!(Tid::<crate::cfg::DefaultConfig>::LEN, 13);

Meanwhile, we have two different checks for TID overflow:

  1. if id > Tid::<C>::BITS {
  2. idx < self.shards.len(),

I've missed something?

loyd commented

Any thoughts? Maybe I missed something. Extra bit would be most welcome =)

hawkw commented

this might be a bug on my part, whoops!