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 337aab8 commit 1d30029
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions src/thread_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ static THREAD_ID_MANAGER: Lazy<Mutex<ThreadIdManager>> =
#[derive(Clone, Copy)]
#[repr(C)]
pub(crate) struct Thread {
id: usize,
bucket: usize,
index: usize,
}
Expand All @@ -68,18 +67,11 @@ impl Thread {
let bucket_size = 1 << bucket;
let index = id - (bucket_size - 1);
Self {
id,
bucket,
index,
}
}

/// The thread ID obtained from the thread ID manager.
#[inline]
pub fn id(&self) -> usize {
self.id
}

/// The bucket this thread's local storage will be in.
#[inline]
pub fn bucket(&self) -> usize {
Expand Down Expand Up @@ -110,7 +102,6 @@ cfg_if::cfg_if! {
static THREAD: UnsafeCell<ThreadWrapper> = UnsafeCell::new(ThreadWrapper {
self_ptr: null(),
thread: Thread {
id: 0,
index: 0,
bucket: 0,
},
Expand Down Expand Up @@ -170,11 +161,12 @@ cfg_if::cfg_if! {
/// Out-of-line slow path for allocating a thread ID.
#[cold]
fn get_slow() -> Thread {
let new = ThreadWrapper::new(THREAD_ID_MANAGER.lock().alloc());
let id = THREAD_ID_MANAGER.lock().alloc();
let new = ThreadWrapper::new(id);
unsafe {
*THREAD.get() = new;
}
THREAD_GUARD.with(|guard| guard.id.set(new.thread.id()));
THREAD_GUARD.with(|guard| guard.id.set(id));
new.thread
}
} else {
Expand Down

0 comments on commit 1d30029

Please sign in to comment.