Skip to content

Commit

Permalink
Thread stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
terrarier2111 committed Jul 20, 2023
1 parent 861ace3 commit 3f6ed91
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/thread_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub(crate) struct Thread {
impl Thread {
#[inline]
fn new(id: usize) -> Self {
let bucket = usize::from(POINTER_WIDTH) - ((id - 1).leading_zeros() as usize) - 1;
let bucket = usize::from(POINTER_WIDTH) - ((id + 1).leading_zeros() as usize) - 1;
let bucket_size = 1 << bucket;
let index = id - (bucket_size - 1);
Self {
Expand All @@ -84,15 +84,13 @@ impl Thread {
/// The bucket this thread's local storage will be in.
#[inline]
pub fn bucket(&self) -> usize {
let bucket = usize::from(POINTER_WIDTH) - ((self.id - 1).leading_zeros() as usize) - 1;
bucket
self.bucket
}

/// The index into the bucket this thread's local storage is in.
#[inline]
pub fn index(&self) -> usize {
let index = self.id() - (self.bucket_size() - 1);
index
self.index
}

/// The size of the bucket this thread's local storage will be in.
Expand Down

0 comments on commit 3f6ed91

Please sign in to comment.