зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1806766 - Update crossbeam-utils to 0.8.14. r=emilio,supply-chain-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D165331
This commit is contained in:
Родитель
8bd3f8b740
Коммит
f467fd6cfe
|
@ -540,7 +540,7 @@ version = "0.1.0"
|
|||
dependencies = [
|
||||
"bits_client",
|
||||
"comedy",
|
||||
"crossbeam-utils 0.8.11",
|
||||
"crossbeam-utils 0.8.14",
|
||||
"libc",
|
||||
"log",
|
||||
"moz_task",
|
||||
|
@ -588,7 +588,7 @@ version = "0.1.2"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b8e3ff9db740167616e528c509b3618046fc05d337f8f3182d300f4aa977d2bb"
|
||||
dependencies = [
|
||||
"crossbeam-utils 0.8.11",
|
||||
"crossbeam-utils 0.8.14",
|
||||
"jobserver",
|
||||
"num_cpus",
|
||||
]
|
||||
|
@ -691,7 +691,7 @@ version = "0.0.1"
|
|||
dependencies = [
|
||||
"base64",
|
||||
"byteorder",
|
||||
"crossbeam-utils 0.8.11",
|
||||
"crossbeam-utils 0.8.14",
|
||||
"cstr",
|
||||
"log",
|
||||
"moz_task",
|
||||
|
@ -985,7 +985,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "c2dd04ddaf88237dc3b8d8f9a3c1004b506b54b3313403944054d23c0870c521"
|
||||
dependencies = [
|
||||
"cfg-if 1.0.0",
|
||||
"crossbeam-utils 0.8.11",
|
||||
"crossbeam-utils 0.8.14",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1007,7 +1007,7 @@ checksum = "715e8152b692bba2d374b53d4875445368fdf21a94751410af607a5ac677d1fc"
|
|||
dependencies = [
|
||||
"cfg-if 1.0.0",
|
||||
"crossbeam-epoch 0.9.13",
|
||||
"crossbeam-utils 0.8.11",
|
||||
"crossbeam-utils 0.8.14",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1033,7 +1033,7 @@ checksum = "01a9af1f4c2ef74bb8aa1f7e19706bc72d03598c8a570bb5de72243c7a9d9d5a"
|
|||
dependencies = [
|
||||
"autocfg",
|
||||
"cfg-if 1.0.0",
|
||||
"crossbeam-utils 0.8.11",
|
||||
"crossbeam-utils 0.8.14",
|
||||
"memoffset 0.7.1",
|
||||
"scopeguard",
|
||||
]
|
||||
|
@ -1070,12 +1070,11 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "crossbeam-utils"
|
||||
version = "0.8.11"
|
||||
version = "0.8.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "51887d4adc7b564537b15adcfb307936f8075dfcd5f00dde9a9f1d29383682bc"
|
||||
checksum = "4fb766fa798726286dbbb842f174001dab8abc7b627a1dd86e0b7222a95d929f"
|
||||
dependencies = [
|
||||
"cfg-if 1.0.0",
|
||||
"once_cell",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -2901,7 +2900,7 @@ name = "kvstore"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"atomic_refcell",
|
||||
"crossbeam-utils 0.8.11",
|
||||
"crossbeam-utils 0.8.14",
|
||||
"cstr",
|
||||
"lazy_static",
|
||||
"libc",
|
||||
|
@ -4457,7 +4456,7 @@ checksum = "258bcdb5ac6dad48491bb2992db6b7cf74878b0384908af124823d118c99683f"
|
|||
dependencies = [
|
||||
"crossbeam-channel",
|
||||
"crossbeam-deque 0.8.2",
|
||||
"crossbeam-utils 0.8.11",
|
||||
"crossbeam-utils 0.8.14",
|
||||
"num_cpus",
|
||||
]
|
||||
|
||||
|
@ -6507,7 +6506,7 @@ dependencies = [
|
|||
name = "xulstore"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"crossbeam-utils 0.8.11",
|
||||
"crossbeam-utils 0.8.14",
|
||||
"cstr",
|
||||
"libc",
|
||||
"log",
|
||||
|
@ -6550,6 +6549,6 @@ checksum = "bf225bcf73bb52cbb496e70475c7bd7a3f769df699c0020f6c7bd9a96dcf0b8d"
|
|||
dependencies = [
|
||||
"byteorder",
|
||||
"crc32fast",
|
||||
"crossbeam-utils 0.8.11",
|
||||
"crossbeam-utils 0.8.14",
|
||||
"flate2",
|
||||
]
|
||||
|
|
|
@ -299,6 +299,11 @@ who = "Mike Hommey <mh+mozilla@glandium.org>"
|
|||
criteria = "safe-to-deploy"
|
||||
delta = "0.8.8 -> 0.8.11"
|
||||
|
||||
[[audits.crossbeam-utils]]
|
||||
who = "Mike Hommey <mh+mozilla@glandium.org>"
|
||||
criteria = "safe-to-deploy"
|
||||
delta = "0.8.11 -> 0.8.14"
|
||||
|
||||
[[audits.crypto-common]]
|
||||
who = "Mike Hommey <mh+mozilla@glandium.org>"
|
||||
criteria = "safe-to-deploy"
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"files":{"CHANGELOG.md":"eb2f46ecf2eee5f591c4d4e789f18735bb1ed771782a5e0f16eab3a77001e7c2","Cargo.toml":"9ce8b596c9789e65bef4c952bdcac84fc88e50ba9ecb01a818036eff4e6ecfec","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"5734ed989dfca1f625b40281ee9f4530f91b2411ec01cb748223e7eb87e201ab","README.md":"2a19af38a52dd965c2d66bb39f90a85b430b51ee9ccb29e9e1978ee7091e5087","benches/atomic_cell.rs":"c927eb3cd1e5ecc4b91adbc3bde98af15ffab4086190792ba64d5cde0e24df3d","build.rs":"4859f9c926c230023e861bf01c4b225b460035faf8cf6240108530efedbb747f","no_atomic.rs":"916ed15218bb7b75a4e0d432430e7134efd27ca43ca8a8766e0c90e89febb602","src/atomic/atomic_cell.rs":"0fc99463e633144c5d59d39c35b5477da1f1b90f5448cadc37454b7f4b97707e","src/atomic/consume.rs":"7a7736fcd64f6473dfea7653559ffc5e1a2a234df43835f8aa8734862145ac15","src/atomic/mod.rs":"94193895fa03cece415e8d7be700b73a9a8a7015774ca821253438607f9b0736","src/atomic/seq_lock.rs":"27182e6b87a9db73c5f6831759f8625f9fcdec3c2828204c444aef04f427735a","src/atomic/seq_lock_wide.rs":"9888dd03116bb89ca36d4ab8d5a0b5032107a2983a7eb8024454263b09080088","src/backoff.rs":"8fd5e3dcccc05860680e49c8498de8096bee9140bcfee8723d97117106a020d0","src/cache_padded.rs":"6a512698115ad0d5a5b163dbd7a83247e1f1c146c4a30f3fc74b952e3b767b59","src/lib.rs":"6f1bcf157abe06ad8458a53e865bf8efab9fad4a9424790147cee8fefb3795d8","src/sync/mod.rs":"59986f559a8f170a4b3247ab2eea2460b09809d87c8110ed88e4e7103d3519dc","src/sync/parker.rs":"91f3a7d4ee8d9e06b6558d180e8a0df08ff5c6cef612b4ce4790f9f75cb34f84","src/sync/sharded_lock.rs":"78433f55ee3defeea348d65abc78e03d63d6a304e09c568b27b403e9ad205771","src/sync/wait_group.rs":"32e946a7581c55f8aa9904527b92b177c538fa0cf7cbcfa1d1f25990582cb6ea","src/thread.rs":"21cf9b3e965529e5c0a6ff8fc1ec846bfe0006c41deb238a149be8d07384e955","tests/atomic_cell.rs":"bf8bc869c922a1cbf929c3b741bae0cae98f2157f572b5a4eb2873d20a407c22","tests/cache_padded.rs":"1bfaff8354c8184e1ee1f902881ca9400b60effb273b0d3f752801a483d2b66d","tests/parker.rs":"6def4721287d9d70b1cfd63ebb34e1c83fbb3376edbad2bc8aac6ef69dd99d20","tests/sharded_lock.rs":"314adeb8a651a28935f7a49c9a261b8fa1fd82bf6a16c865a5aced6216d7e40b","tests/thread.rs":"9a7d7d3028c552fd834c68598b04a1cc252a816bc20ab62cec060d6cd09cab10","tests/wait_group.rs":"02661c2a820a5abe8b0c8fe15a6650aead707b57cdda0610d1b09a2680ed6969"},"package":"51887d4adc7b564537b15adcfb307936f8075dfcd5f00dde9a9f1d29383682bc"}
|
||||
{"files":{"CHANGELOG.md":"fbcdd2c242af3f8eab76ca3dff71f4c9b1d569db6039ab2f7e331417122d121d","Cargo.toml":"0916d9452f9f79784ac417256b661caa0c95f1b0d3107ad3af2991026707fa61","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"5734ed989dfca1f625b40281ee9f4530f91b2411ec01cb748223e7eb87e201ab","README.md":"2a19af38a52dd965c2d66bb39f90a85b430b51ee9ccb29e9e1978ee7091e5087","benches/atomic_cell.rs":"c927eb3cd1e5ecc4b91adbc3bde98af15ffab4086190792ba64d5cde0e24df3d","build-common.rs":"502cb7494549bed6fa10ac7bea36e880eeb60290dc69b679ac5c92b376469562","build.rs":"ec1d47ec36b3670a6e67955a104851ee7125616888e78bd03b93304e12cd1c50","no_atomic.rs":"3314524d2afa0360c947455a6e6566fb54ebf909c99479ca3b7435741fd3293e","src/atomic/atomic_cell.rs":"0fc99463e633144c5d59d39c35b5477da1f1b90f5448cadc37454b7f4b97707e","src/atomic/consume.rs":"7a7736fcd64f6473dfea7653559ffc5e1a2a234df43835f8aa8734862145ac15","src/atomic/mod.rs":"94193895fa03cece415e8d7be700b73a9a8a7015774ca821253438607f9b0736","src/atomic/seq_lock.rs":"27182e6b87a9db73c5f6831759f8625f9fcdec3c2828204c444aef04f427735a","src/atomic/seq_lock_wide.rs":"9888dd03116bb89ca36d4ab8d5a0b5032107a2983a7eb8024454263b09080088","src/backoff.rs":"8fd5e3dcccc05860680e49c8498de8096bee9140bcfee8723d97117106a020d0","src/cache_padded.rs":"8bb8925e2df44224ffa29f31a2f9c08d88d8bd3df6c1ce47003598225055fdb5","src/lib.rs":"6f1bcf157abe06ad8458a53e865bf8efab9fad4a9424790147cee8fefb3795d8","src/sync/mod.rs":"eca73c04f821859b8434d2b93db87d160dc6a3f65498ca201cd40d732ca4c134","src/sync/once_lock.rs":"c03dc9c05a817e087dccf8b682f7307501542805533551da3c2bab442bc40743","src/sync/parker.rs":"91f3a7d4ee8d9e06b6558d180e8a0df08ff5c6cef612b4ce4790f9f75cb34f84","src/sync/sharded_lock.rs":"6391b3b99b194b8e0888446c2dec340e4fb095753bcf0c1a80bc654f9c8be0e3","src/sync/wait_group.rs":"3e339aab014f50e214fea535c841755113ea058153378ed54e50a4acb403c937","src/thread.rs":"21cf9b3e965529e5c0a6ff8fc1ec846bfe0006c41deb238a149be8d07384e955","tests/atomic_cell.rs":"bf8bc869c922a1cbf929c3b741bae0cae98f2157f572b5a4eb2873d20a407c22","tests/cache_padded.rs":"1bfaff8354c8184e1ee1f902881ca9400b60effb273b0d3f752801a483d2b66d","tests/parker.rs":"6def4721287d9d70b1cfd63ebb34e1c83fbb3376edbad2bc8aac6ef69dd99d20","tests/sharded_lock.rs":"314adeb8a651a28935f7a49c9a261b8fa1fd82bf6a16c865a5aced6216d7e40b","tests/thread.rs":"9a7d7d3028c552fd834c68598b04a1cc252a816bc20ab62cec060d6cd09cab10","tests/wait_group.rs":"02661c2a820a5abe8b0c8fe15a6650aead707b57cdda0610d1b09a2680ed6969"},"package":"4fb766fa798726286dbbb842f174001dab8abc7b627a1dd86e0b7222a95d929f"}
|
|
@ -1,3 +1,18 @@
|
|||
# Version 0.8.14
|
||||
|
||||
- Fix build script bug introduced in 0.8.13. (#932)
|
||||
|
||||
# Version 0.8.13
|
||||
|
||||
**Note:** This release has been yanked due to regression fixed in 0.8.14.
|
||||
|
||||
- Improve support for custom targets. (#922)
|
||||
|
||||
# Version 0.8.12
|
||||
|
||||
- Removes the dependency on the `once_cell` crate to restore the MSRV. (#913)
|
||||
- Work around [rust-lang#98302](https://github.com/rust-lang/rust/issues/98302), which causes compile error on windows-gnu when LTO is enabled. (#913)
|
||||
|
||||
# Version 0.8.11
|
||||
|
||||
- Bump the minimum supported Rust version to 1.38. (#877)
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
edition = "2018"
|
||||
rust-version = "1.38"
|
||||
name = "crossbeam-utils"
|
||||
version = "0.8.11"
|
||||
version = "0.8.14"
|
||||
description = "Utilities for concurrent programming"
|
||||
homepage = "https://github.com/crossbeam-rs/crossbeam/tree/master/crossbeam-utils"
|
||||
readme = "README.md"
|
||||
|
@ -35,10 +35,6 @@ repository = "https://github.com/crossbeam-rs/crossbeam"
|
|||
[dependencies.cfg-if]
|
||||
version = "1"
|
||||
|
||||
[dependencies.once_cell]
|
||||
version = "1"
|
||||
optional = true
|
||||
|
||||
[dev-dependencies.rand]
|
||||
version = "0.8"
|
||||
|
||||
|
@ -48,7 +44,7 @@ version = "1"
|
|||
[features]
|
||||
default = ["std"]
|
||||
nightly = []
|
||||
std = ["once_cell"]
|
||||
std = []
|
||||
|
||||
[target."cfg(crossbeam_loom)".dependencies.loom]
|
||||
version = "0.5"
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
// The target triplets have the form of 'arch-vendor-system'.
|
||||
//
|
||||
// When building for Linux (e.g. the 'system' part is
|
||||
// 'linux-something'), replace the vendor with 'unknown'
|
||||
// so that mapping to rust standard targets happens correctly.
|
||||
fn convert_custom_linux_target(target: String) -> String {
|
||||
let mut parts: Vec<&str> = target.split('-').collect();
|
||||
let system = parts.get(2);
|
||||
if system == Some(&"linux") {
|
||||
parts[1] = "unknown";
|
||||
};
|
||||
parts.join("-")
|
||||
}
|
|
@ -27,10 +27,11 @@
|
|||
use std::env;
|
||||
|
||||
include!("no_atomic.rs");
|
||||
include!("build-common.rs");
|
||||
|
||||
fn main() {
|
||||
let target = match env::var("TARGET") {
|
||||
Ok(target) => target,
|
||||
Ok(target) => convert_custom_linux_target(target),
|
||||
Err(e) => {
|
||||
println!(
|
||||
"cargo:warning={}: unable to get TARGET environment variable: {}",
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
// It is not intended for manual editing.
|
||||
|
||||
const NO_ATOMIC_CAS: &[&str] = &[
|
||||
"armv4t-none-eabi",
|
||||
"armv5te-none-eabi",
|
||||
"avr-unknown-gnu-atmega328",
|
||||
"bpfeb-unknown-none",
|
||||
"bpfel-unknown-none",
|
||||
|
@ -10,6 +12,7 @@ const NO_ATOMIC_CAS: &[&str] = &[
|
|||
"riscv32im-unknown-none-elf",
|
||||
"riscv32imc-unknown-none-elf",
|
||||
"thumbv4t-none-eabi",
|
||||
"thumbv5te-none-eabi",
|
||||
"thumbv6m-none-eabi",
|
||||
];
|
||||
|
||||
|
@ -18,7 +21,9 @@ const NO_ATOMIC_64: &[&str] = &[
|
|||
"arm-linux-androideabi",
|
||||
"armebv7r-none-eabi",
|
||||
"armebv7r-none-eabihf",
|
||||
"armv4t-none-eabi",
|
||||
"armv4t-unknown-linux-gnueabi",
|
||||
"armv5te-none-eabi",
|
||||
"armv5te-unknown-linux-gnueabi",
|
||||
"armv5te-unknown-linux-musleabi",
|
||||
"armv5te-unknown-linux-uclibceabi",
|
||||
|
@ -32,6 +37,7 @@ const NO_ATOMIC_64: &[&str] = &[
|
|||
"mips-unknown-linux-musl",
|
||||
"mips-unknown-linux-uclibc",
|
||||
"mipsel-sony-psp",
|
||||
"mipsel-sony-psx",
|
||||
"mipsel-unknown-linux-gnu",
|
||||
"mipsel-unknown-linux-musl",
|
||||
"mipsel-unknown-linux-uclibc",
|
||||
|
@ -55,6 +61,7 @@ const NO_ATOMIC_64: &[&str] = &[
|
|||
"riscv32imac-unknown-xous-elf",
|
||||
"riscv32imc-unknown-none-elf",
|
||||
"thumbv4t-none-eabi",
|
||||
"thumbv5te-none-eabi",
|
||||
"thumbv6m-none-eabi",
|
||||
"thumbv7em-none-eabi",
|
||||
"thumbv7em-none-eabihf",
|
||||
|
@ -67,6 +74,7 @@ const NO_ATOMIC_64: &[&str] = &[
|
|||
#[allow(dead_code)] // Only crossbeam-utils uses this.
|
||||
const NO_ATOMIC: &[&str] = &[
|
||||
"avr-unknown-gnu-atmega328",
|
||||
"mipsel-sony-psx",
|
||||
"msp430-none-elf",
|
||||
"riscv32i-unknown-none-elf",
|
||||
"riscv32im-unknown-none-elf",
|
||||
|
|
|
@ -39,9 +39,9 @@ use core::ops::{Deref, DerefMut};
|
|||
/// let addr1 = &*array[0] as *const i8 as usize;
|
||||
/// let addr2 = &*array[1] as *const i8 as usize;
|
||||
///
|
||||
/// assert!(addr2 - addr1 >= 64);
|
||||
/// assert_eq!(addr1 % 64, 0);
|
||||
/// assert_eq!(addr2 % 64, 0);
|
||||
/// assert!(addr2 - addr1 >= 32);
|
||||
/// assert_eq!(addr1 % 32, 0);
|
||||
/// assert_eq!(addr2 % 32, 0);
|
||||
/// ```
|
||||
///
|
||||
/// When building a concurrent queue with a head and a tail index, it is wise to place them in
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
//! * [`ShardedLock`], a sharded reader-writer lock with fast concurrent reads.
|
||||
//! * [`WaitGroup`], for synchronizing the beginning or end of some computation.
|
||||
|
||||
#[cfg(not(crossbeam_loom))]
|
||||
mod once_lock;
|
||||
mod parker;
|
||||
#[cfg(not(crossbeam_loom))]
|
||||
mod sharded_lock;
|
||||
|
|
|
@ -0,0 +1,103 @@
|
|||
// Based on unstable std::sync::OnceLock.
|
||||
//
|
||||
// Source: https://github.com/rust-lang/rust/blob/8e9c93df464b7ada3fc7a1c8ccddd9dcb24ee0a0/library/std/src/sync/once_lock.rs
|
||||
|
||||
use core::cell::UnsafeCell;
|
||||
use core::mem::MaybeUninit;
|
||||
use core::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::Once;
|
||||
|
||||
pub(crate) struct OnceLock<T> {
|
||||
once: Once,
|
||||
// Once::is_completed requires Rust 1.43, so use this to track of whether they have been initialized.
|
||||
is_initialized: AtomicBool,
|
||||
value: UnsafeCell<MaybeUninit<T>>,
|
||||
// Unlike std::sync::OnceLock, we don't need PhantomData here because
|
||||
// we don't use #[may_dangle].
|
||||
}
|
||||
|
||||
unsafe impl<T: Sync + Send> Sync for OnceLock<T> {}
|
||||
unsafe impl<T: Send> Send for OnceLock<T> {}
|
||||
|
||||
impl<T> OnceLock<T> {
|
||||
/// Creates a new empty cell.
|
||||
#[must_use]
|
||||
pub(crate) const fn new() -> Self {
|
||||
Self {
|
||||
once: Once::new(),
|
||||
is_initialized: AtomicBool::new(false),
|
||||
value: UnsafeCell::new(MaybeUninit::uninit()),
|
||||
}
|
||||
}
|
||||
|
||||
/// Gets the contents of the cell, initializing it with `f` if the cell
|
||||
/// was empty.
|
||||
///
|
||||
/// Many threads may call `get_or_init` concurrently with different
|
||||
/// initializing functions, but it is guaranteed that only one function
|
||||
/// will be executed.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// If `f` panics, the panic is propagated to the caller, and the cell
|
||||
/// remains uninitialized.
|
||||
///
|
||||
/// It is an error to reentrantly initialize the cell from `f`. The
|
||||
/// exact outcome is unspecified. Current implementation deadlocks, but
|
||||
/// this may be changed to a panic in the future.
|
||||
pub(crate) fn get_or_init<F>(&self, f: F) -> &T
|
||||
where
|
||||
F: FnOnce() -> T,
|
||||
{
|
||||
// Fast path check
|
||||
if self.is_initialized() {
|
||||
// SAFETY: The inner value has been initialized
|
||||
return unsafe { self.get_unchecked() };
|
||||
}
|
||||
self.initialize(f);
|
||||
|
||||
debug_assert!(self.is_initialized());
|
||||
|
||||
// SAFETY: The inner value has been initialized
|
||||
unsafe { self.get_unchecked() }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn is_initialized(&self) -> bool {
|
||||
self.is_initialized.load(Ordering::Acquire)
|
||||
}
|
||||
|
||||
#[cold]
|
||||
fn initialize<F>(&self, f: F)
|
||||
where
|
||||
F: FnOnce() -> T,
|
||||
{
|
||||
let slot = self.value.get().cast::<T>();
|
||||
let is_initialized = &self.is_initialized;
|
||||
|
||||
self.once.call_once(|| {
|
||||
let value = f();
|
||||
unsafe {
|
||||
slot.write(value);
|
||||
}
|
||||
is_initialized.store(true, Ordering::Release);
|
||||
});
|
||||
}
|
||||
|
||||
/// # Safety
|
||||
///
|
||||
/// The value must be initialized
|
||||
unsafe fn get_unchecked(&self) -> &T {
|
||||
debug_assert!(self.is_initialized());
|
||||
&*self.value.get().cast::<T>()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Drop for OnceLock<T> {
|
||||
fn drop(&mut self) {
|
||||
if self.is_initialized() {
|
||||
// SAFETY: The inner value has been initialized
|
||||
unsafe { self.value.get().cast::<T>().drop_in_place() };
|
||||
}
|
||||
}
|
||||
}
|
|
@ -9,8 +9,8 @@ use std::sync::{LockResult, PoisonError, TryLockError, TryLockResult};
|
|||
use std::sync::{Mutex, RwLock, RwLockReadGuard, RwLockWriteGuard};
|
||||
use std::thread::{self, ThreadId};
|
||||
|
||||
use crate::sync::once_lock::OnceLock;
|
||||
use crate::CachePadded;
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
/// The number of shards per sharded lock. Must be a power of two.
|
||||
const NUM_SHARDS: usize = 8;
|
||||
|
@ -583,13 +583,17 @@ struct ThreadIndices {
|
|||
next_index: usize,
|
||||
}
|
||||
|
||||
static THREAD_INDICES: Lazy<Mutex<ThreadIndices>> = Lazy::new(|| {
|
||||
Mutex::new(ThreadIndices {
|
||||
mapping: HashMap::new(),
|
||||
free_list: Vec::new(),
|
||||
next_index: 0,
|
||||
})
|
||||
});
|
||||
fn thread_indices() -> &'static Mutex<ThreadIndices> {
|
||||
static THREAD_INDICES: OnceLock<Mutex<ThreadIndices>> = OnceLock::new();
|
||||
fn init() -> Mutex<ThreadIndices> {
|
||||
Mutex::new(ThreadIndices {
|
||||
mapping: HashMap::new(),
|
||||
free_list: Vec::new(),
|
||||
next_index: 0,
|
||||
})
|
||||
}
|
||||
THREAD_INDICES.get_or_init(init)
|
||||
}
|
||||
|
||||
/// A registration of a thread with an index.
|
||||
///
|
||||
|
@ -601,7 +605,7 @@ struct Registration {
|
|||
|
||||
impl Drop for Registration {
|
||||
fn drop(&mut self) {
|
||||
let mut indices = THREAD_INDICES.lock().unwrap();
|
||||
let mut indices = thread_indices().lock().unwrap();
|
||||
indices.mapping.remove(&self.thread_id);
|
||||
indices.free_list.push(self.index);
|
||||
}
|
||||
|
@ -610,7 +614,7 @@ impl Drop for Registration {
|
|||
thread_local! {
|
||||
static REGISTRATION: Registration = {
|
||||
let thread_id = thread::current().id();
|
||||
let mut indices = THREAD_INDICES.lock().unwrap();
|
||||
let mut indices = thread_indices().lock().unwrap();
|
||||
|
||||
let index = match indices.free_list.pop() {
|
||||
Some(i) => i,
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
// Necessary for using `Mutex<usize>` for conditional variables
|
||||
#![allow(clippy::mutex_atomic)]
|
||||
|
||||
use crate::primitive::sync::{Arc, Condvar, Mutex};
|
||||
use std::fmt;
|
||||
|
||||
|
@ -42,6 +39,7 @@ use std::fmt;
|
|||
///
|
||||
/// // Block until all threads have finished their work.
|
||||
/// wg.wait();
|
||||
/// # std::thread::sleep(std::time::Duration::from_millis(500)); // wait for background threads closed: https://github.com/rust-lang/miri/issues/1371
|
||||
/// ```
|
||||
///
|
||||
/// [`Barrier`]: std::sync::Barrier
|
||||
|
@ -100,6 +98,7 @@ impl WaitGroup {
|
|||
///
|
||||
/// // Block until both threads have reached `wait()`.
|
||||
/// wg.wait();
|
||||
/// # std::thread::sleep(std::time::Duration::from_millis(500)); // wait for background threads closed: https://github.com/rust-lang/miri/issues/1371
|
||||
/// ```
|
||||
pub fn wait(self) {
|
||||
if *self.inner.count.lock().unwrap() == 1 {
|
||||
|
|
Загрузка…
Ссылка в новой задаче