summaryrefslogtreecommitdiffstats
path: root/vendor/sharded-slab/src/tid.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-19 09:26:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-19 09:26:03 +0000
commit9918693037dce8aa4bb6f08741b6812923486c18 (patch)
tree21d2b40bec7e6a7ea664acee056eb3d08e15a1cf /vendor/sharded-slab/src/tid.rs
parentReleasing progress-linux version 1.75.0+dfsg1-5~progress7.99u1. (diff)
downloadrustc-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 'vendor/sharded-slab/src/tid.rs')
-rw-r--r--vendor/sharded-slab/src/tid.rs20
1 files changed, 18 insertions, 2 deletions
diff --git a/vendor/sharded-slab/src/tid.rs b/vendor/sharded-slab/src/tid.rs
index 57d64f970..f2cb7e0d9 100644
--- a/vendor/sharded-slab/src/tid.rs
+++ b/vendor/sharded-slab/src/tid.rs
@@ -12,7 +12,6 @@ use std::{
collections::VecDeque,
fmt,
marker::PhantomData,
- sync::PoisonError,
};
/// Uniquely identifies a thread.
@@ -123,7 +122,7 @@ impl<C> Eq for Tid<C> {}
impl<C: cfg::Config> Clone for Tid<C> {
fn clone(&self) -> Self {
- Self::new(self.id)
+ *self
}
}
@@ -186,9 +185,26 @@ impl Registration {
#[cfg(not(all(loom, any(feature = "loom", test))))]
impl Drop for Registration {
fn drop(&mut self) {
+ use std::sync::PoisonError;
+
if let Some(id) = self.0.get() {
let mut free_list = REGISTRY.free.lock().unwrap_or_else(PoisonError::into_inner);
free_list.push_back(id);
}
}
}
+
+#[cfg(all(test, not(loom)))]
+pub(crate) fn with<R>(tid: usize, f: impl FnOnce() -> R) -> R {
+ struct Guard(Option<usize>);
+
+ impl Drop for Guard {
+ fn drop(&mut self) {
+ REGISTRATION.with(|r| r.0.set(self.0.take()));
+ }
+ }
+
+ let prev = REGISTRATION.with(|r| r.0.replace(Some(tid)));
+ let _guard = Guard(prev);
+ f()
+}