Skip to content

Commit

Permalink
feat: emit a nicer panic when thread count overflows MAX_SHARDS (#64)
Browse files Browse the repository at this point in the history
* Emit a nicer panic when thread count overflows `MAX_SHARDS`

Tackles #62 (comment)

* Replace `if cond { panic` with `assert!`

TODO: negate the condition in the assertion

Co-authored-by: Eliza Weisman <eliza@buoyant.io>

* Negate the condition in the assertion

Co-authored-by: Eliza Weisman <eliza@buoyant.io>
  • Loading branch information
danielhenrymantilla and hawkw committed Oct 11, 2021
1 parent 2403467 commit f1ed058
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/shard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,13 @@ where
let tid = Tid::<C>::current();
test_println!("current: {:?}", tid);
let idx = tid.as_usize();
assert!(
idx < self.shards.len(),
"Thread count overflowed the configured max count. \
Thread index = {}, max threads = {}.",
idx,
C::MAX_SHARDS,
);
// It's okay for this to be relaxed. The value is only ever stored by
// the thread that corresponds to the index, and we are that thread.
let shard = self.shards[idx].load(Relaxed).unwrap_or_else(|| {
Expand Down

0 comments on commit f1ed058

Please sign in to comment.