Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repository = "https://github.com/Amanieu/thread_local-rs"
readme = "README.md"
keywords = ["thread_local", "concurrent", "thread"]
edition = "2021"
rust-version = "1.63"
rust-version = "1.80"

[features]
# this feature provides performance improvements using nightly features
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ thread_local = "1.1"

## Minimum Rust version

This crate's minimum supported Rust version (MSRV) is 1.63.0.
This crate's minimum supported Rust version (MSRV) is 1.80.0.

## License

Expand Down
11 changes: 5 additions & 6 deletions src/thread_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ use std::sync::Mutex;
/// indefinitely when it is used by many short-lived threads.
struct ThreadIdManager {
free_from: usize,
free_list: Option<BinaryHeap<Reverse<usize>>>,
free_list: BinaryHeap<Reverse<usize>>,
}

impl ThreadIdManager {
const fn new() -> Self {
Self {
free_from: 0,
free_list: None,
free_list: BinaryHeap::new(),
}
}

fn alloc(&mut self) -> usize {
if let Some(id) = self.free_list.as_mut().and_then(|heap| heap.pop()) {
if let Some(id) = self.free_list.pop() {
id.0
} else {
// `free_from` can't overflow as each thread takes up at least 2 bytes of memory and
Expand All @@ -40,9 +40,7 @@ impl ThreadIdManager {
}

fn free(&mut self, id: usize) {
self.free_list
.get_or_insert_with(BinaryHeap::new)
.push(Reverse(id));
self.free_list.push(Reverse(id));
}
}

Expand All @@ -57,6 +55,7 @@ pub(crate) struct Thread {
/// The index into the bucket this thread's local storage is in.
pub(crate) index: usize,
}

impl Thread {
pub(crate) fn new(id: usize) -> Self {
let bucket = (usize::BITS as usize) - ((id + 1).leading_zeros() as usize) - 1;
Expand Down