diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-19 09:26:03 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-19 09:26:03 +0000 |
commit | 9918693037dce8aa4bb6f08741b6812923486c18 (patch) | |
tree | 21d2b40bec7e6a7ea664acee056eb3d08e15a1cf /compiler/rustc_data_structures/src/sync/worker_local.rs | |
parent | Releasing progress-linux version 1.75.0+dfsg1-5~progress7.99u1. (diff) | |
download | rustc-9918693037dce8aa4bb6f08741b6812923486c18.tar.xz rustc-9918693037dce8aa4bb6f08741b6812923486c18.zip |
Merging upstream version 1.76.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_data_structures/src/sync/worker_local.rs')
-rw-r--r-- | compiler/rustc_data_structures/src/sync/worker_local.rs | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/compiler/rustc_data_structures/src/sync/worker_local.rs b/compiler/rustc_data_structures/src/sync/worker_local.rs index ffafdba13..b34d3dd90 100644 --- a/compiler/rustc_data_structures/src/sync/worker_local.rs +++ b/compiler/rustc_data_structures/src/sync/worker_local.rs @@ -1,6 +1,7 @@ use parking_lot::Mutex; use std::cell::Cell; use std::cell::OnceCell; +use std::num::NonZeroUsize; use std::ops::Deref; use std::ptr; use std::sync::Arc; @@ -30,7 +31,7 @@ impl RegistryId { } struct RegistryData { - thread_limit: usize, + thread_limit: NonZeroUsize, threads: Mutex<usize>, } @@ -60,7 +61,7 @@ thread_local! { impl Registry { /// Creates a registry which can hold up to `thread_limit` threads. - pub fn new(thread_limit: usize) -> Self { + pub fn new(thread_limit: NonZeroUsize) -> Self { Registry(Arc::new(RegistryData { thread_limit, threads: Mutex::new(0) })) } @@ -73,7 +74,7 @@ impl Registry { /// Panics if the thread limit is hit or if the thread already has an associated registry. pub fn register(&self) { let mut threads = self.0.threads.lock(); - if *threads < self.0.thread_limit { + if *threads < self.0.thread_limit.get() { REGISTRY.with(|registry| { if registry.get().is_some() { drop(threads); @@ -126,7 +127,9 @@ impl<T> WorkerLocal<T> { { let registry = Registry::current(); WorkerLocal { - locals: (0..registry.0.thread_limit).map(|i| CacheAligned(initial(i))).collect(), + locals: (0..registry.0.thread_limit.get()) + .map(|i| CacheAligned(initial(i))) + .collect(), registry, } } |