diff options
author | Jeff Vander Stoep <jeffv@google.com> | 2024-02-01 22:45:56 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2024-02-01 22:45:56 +0000 |
commit | ac38886e152cf4d7bbd2ba6922df98e3f4f5d646 (patch) | |
tree | 5a8ef7749b2793766d97ab82661b46f856ff7df4 | |
parent | f56f35bc218616237b290b2de82ff3a341959e58 (diff) | |
parent | 38d6b2b498013ee01629b69cacd28658b2afef9f (diff) | |
download | crossbeam-queue-ac38886e152cf4d7bbd2ba6922df98e3f4f5d646.tar.gz |
Upgrade crossbeam-queue to 0.3.11 am: 38d6b2b498
Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/crossbeam-queue/+/2943925
Change-Id: I9d19c70d7f393a9ba77d4ce606e0f341ac7bb94c
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r-- | .cargo_vcs_info.json | 2 | ||||
-rw-r--r-- | Android.bp | 19 | ||||
-rw-r--r-- | CHANGELOG.md | 16 | ||||
-rw-r--r-- | Cargo.toml | 11 | ||||
-rw-r--r-- | Cargo.toml.orig | 13 | ||||
-rw-r--r-- | METADATA | 25 | ||||
-rw-r--r-- | README.md | 4 | ||||
-rw-r--r-- | build-common.rs | 13 | ||||
-rw-r--r-- | build.rs | 41 | ||||
-rw-r--r-- | no_atomic.rs | 82 | ||||
-rw-r--r-- | src/array_queue.rs | 63 | ||||
-rw-r--r-- | src/lib.rs | 18 | ||||
-rw-r--r-- | src/seg_queue.rs | 10 |
13 files changed, 93 insertions, 224 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index 1c674b3..f326d97 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,6 +1,6 @@ { "git": { - "sha1": "366276a4dde8bd6b4bdab531c09e6ab1ff38c407" + "sha1": "9c3182abebb36bdc9446d75d4644190fef70fa01" }, "path_in_vcs": "crossbeam-queue" }
\ No newline at end of file @@ -44,21 +44,20 @@ rust_test { host_supported: true, crate_name: "array_queue", cargo_env_compat: true, - cargo_pkg_version: "0.3.8", + cargo_pkg_version: "0.3.11", srcs: ["tests/array_queue.rs"], test_suites: ["general-tests"], auto_gen_config: true, test_options: { unit_test: true, }, - edition: "2018", + edition: "2021", features: [ "alloc", "default", "std", ], rustlibs: [ - "libcfg_if", "libcrossbeam_queue", "libcrossbeam_utils", "librand", @@ -70,21 +69,20 @@ rust_test { host_supported: true, crate_name: "seg_queue", cargo_env_compat: true, - cargo_pkg_version: "0.3.8", + cargo_pkg_version: "0.3.11", srcs: ["tests/seg_queue.rs"], test_suites: ["general-tests"], auto_gen_config: true, test_options: { unit_test: true, }, - edition: "2018", + edition: "2021", features: [ "alloc", "default", "std", ], rustlibs: [ - "libcfg_if", "libcrossbeam_queue", "libcrossbeam_utils", "librand", @@ -96,18 +94,15 @@ rust_library { host_supported: true, crate_name: "crossbeam_queue", cargo_env_compat: true, - cargo_pkg_version: "0.3.8", + cargo_pkg_version: "0.3.11", srcs: ["src/lib.rs"], - edition: "2018", + edition: "2021", features: [ "alloc", "default", "std", ], - rustlibs: [ - "libcfg_if", - "libcrossbeam_utils", - ], + rustlibs: ["libcrossbeam_utils"], apex_available: [ "//apex_available:platform", "com.android.virt", diff --git a/CHANGELOG.md b/CHANGELOG.md index 79aaacd..68c9bbd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,19 @@ +# Version 0.3.11 + +- Remove dependency on `cfg-if`. (#1072) + +# Version 0.3.10 + +- Relax the minimum supported Rust version to 1.60. (#1056) +- Implement `UnwindSafe` and `RefUnwindSafe` for `ArrayQueue` and `SegQueue`. (#1053) +- Optimize `Drop` implementation of `ArrayQueue`. (#1057) + +# Version 0.3.9 + +- Bump the minimum supported Rust version to 1.61. (#1037) +- Improve support for targets without atomic CAS. (#1037) +- Remove build script. (#1037) + # Version 0.3.8 - Fix build script bug introduced in 0.3.7. (#932) @@ -10,10 +10,10 @@ # See Cargo.toml.orig for the original contents. [package] -edition = "2018" -rust-version = "1.38" +edition = "2021" +rust-version = "1.60" name = "crossbeam-queue" -version = "0.3.8" +version = "0.3.11" description = "Concurrent queues" homepage = "https://github.com/crossbeam-rs/crossbeam/tree/master/crossbeam-queue" readme = "README.md" @@ -32,11 +32,8 @@ categories = [ license = "MIT OR Apache-2.0" repository = "https://github.com/crossbeam-rs/crossbeam" -[dependencies.cfg-if] -version = "1" - [dependencies.crossbeam-utils] -version = "0.8.5" +version = "0.8.18" default-features = false [dev-dependencies.rand] diff --git a/Cargo.toml.orig b/Cargo.toml.orig index 27c386c..410122c 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -4,9 +4,9 @@ name = "crossbeam-queue" # - Update CHANGELOG.md # - Update README.md # - Create "crossbeam-queue-X.Y.Z" git tag -version = "0.3.8" -edition = "2018" -rust-version = "1.38" +version = "0.3.11" +edition = "2021" +rust-version = "1.60" license = "MIT OR Apache-2.0" repository = "https://github.com/crossbeam-rs/crossbeam" homepage = "https://github.com/crossbeam-rs/crossbeam/tree/master/crossbeam-queue" @@ -37,12 +37,7 @@ alloc = [] nightly = ["crossbeam-utils/nightly"] [dependencies] -cfg-if = "1" - -[dependencies.crossbeam-utils] -version = "0.8.5" -path = "../crossbeam-utils" -default-features = false +crossbeam-utils = { version = "0.8.18", path = "../crossbeam-utils", default-features = false } [dev-dependencies] rand = "0.8" @@ -1,23 +1,20 @@ # This project was upgraded with external_updater. -# Usage: tools/external_updater/updater.sh update rust/crates/crossbeam-queue -# For more info, check https://cs.android.com/android/platform/superproject/+/master:tools/external_updater/README.md +# Usage: tools/external_updater/updater.sh update external/rust/crates/crossbeam-queue +# For more info, check https://cs.android.com/android/platform/superproject/+/main:tools/external_updater/README.md name: "crossbeam-queue" description: "Concurrent queues" third_party { - url { - type: HOMEPAGE - value: "https://crates.io/crates/crossbeam-queue" - } - url { - type: ARCHIVE - value: "https://static.crates.io/crates/crossbeam-queue/crossbeam-queue-0.3.8.crate" - } - version: "0.3.8" license_type: NOTICE last_upgrade_date { - year: 2022 - month: 12 - day: 8 + year: 2024 + month: 2 + day: 1 + } + homepage: "https://crates.io/crates/crossbeam-queue" + identifier { + type: "Archive" + value: "https://static.crates.io/crates/crossbeam-queue/crossbeam-queue-0.3.11.crate" + version: "0.3.11" } } @@ -8,7 +8,7 @@ https://github.com/crossbeam-rs/crossbeam/tree/master/crossbeam-queue#license) https://crates.io/crates/crossbeam-queue) [![Documentation](https://docs.rs/crossbeam-queue/badge.svg)]( https://docs.rs/crossbeam-queue) -[![Rust 1.38+](https://img.shields.io/badge/rust-1.38+-lightgray.svg)]( +[![Rust 1.60+](https://img.shields.io/badge/rust-1.60+-lightgray.svg)]( https://www.rust-lang.org) [![chat](https://img.shields.io/discord/569610676205781012.svg?logo=discord)](https://discord.com/invite/JXYwgWZ) @@ -36,7 +36,7 @@ crossbeam-queue = "0.3" Crossbeam Queue supports stable Rust releases going back at least six months, and every time the minimum supported Rust version is increased, a new minor -version is released. Currently, the minimum supported Rust version is 1.38. +version is released. Currently, the minimum supported Rust version is 1.60. ## License diff --git a/build-common.rs b/build-common.rs deleted file mode 100644 index e91bb4d..0000000 --- a/build-common.rs +++ /dev/null @@ -1,13 +0,0 @@ -// 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("-") -} diff --git a/build.rs b/build.rs deleted file mode 100644 index 6975dd8..0000000 --- a/build.rs +++ /dev/null @@ -1,41 +0,0 @@ -// The rustc-cfg listed below are considered public API, but it is *unstable* -// and outside of the normal semver guarantees: -// -// - `crossbeam_no_atomic_cas` -// Assume the target does *not* support atomic CAS operations. -// This is usually detected automatically by the build script, but you may -// need to enable it manually when building for custom targets or using -// non-cargo build systems that don't run the build script. -// -// With the exceptions mentioned above, the rustc-cfg emitted by the build -// script are *not* public API. - -#![warn(rust_2018_idioms)] - -use std::env; - -include!("no_atomic.rs"); -include!("build-common.rs"); - -fn main() { - let target = match env::var("TARGET") { - Ok(target) => convert_custom_linux_target(target), - Err(e) => { - println!( - "cargo:warning={}: unable to get TARGET environment variable: {}", - env!("CARGO_PKG_NAME"), - e - ); - return; - } - }; - - // Note that this is `no_`*, not `has_*`. This allows treating as the latest - // stable rustc is used when the build script doesn't run. This is useful - // for non-cargo build systems that don't run the build script. - if NO_ATOMIC_CAS.contains(&&*target) { - println!("cargo:rustc-cfg=crossbeam_no_atomic_cas"); - } - - println!("cargo:rerun-if-changed=no_atomic.rs"); -} diff --git a/no_atomic.rs b/no_atomic.rs deleted file mode 100644 index 8ce0d31..0000000 --- a/no_atomic.rs +++ /dev/null @@ -1,82 +0,0 @@ -// This file is @generated by no_atomic.sh. -// 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", - "msp430-none-elf", - "riscv32i-unknown-none-elf", - "riscv32im-unknown-none-elf", - "riscv32imc-unknown-none-elf", - "thumbv4t-none-eabi", - "thumbv5te-none-eabi", - "thumbv6m-none-eabi", -]; - -#[allow(dead_code)] // Only crossbeam-utils uses this. -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", - "armv6k-nintendo-3ds", - "armv7r-none-eabi", - "armv7r-none-eabihf", - "avr-unknown-gnu-atmega328", - "hexagon-unknown-linux-musl", - "m68k-unknown-linux-gnu", - "mips-unknown-linux-gnu", - "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", - "mipsel-unknown-none", - "mipsisa32r6-unknown-linux-gnu", - "mipsisa32r6el-unknown-linux-gnu", - "msp430-none-elf", - "powerpc-unknown-freebsd", - "powerpc-unknown-linux-gnu", - "powerpc-unknown-linux-gnuspe", - "powerpc-unknown-linux-musl", - "powerpc-unknown-netbsd", - "powerpc-unknown-openbsd", - "powerpc-wrs-vxworks", - "powerpc-wrs-vxworks-spe", - "riscv32gc-unknown-linux-gnu", - "riscv32gc-unknown-linux-musl", - "riscv32i-unknown-none-elf", - "riscv32im-unknown-none-elf", - "riscv32imac-unknown-none-elf", - "riscv32imac-unknown-xous-elf", - "riscv32imc-unknown-none-elf", - "thumbv4t-none-eabi", - "thumbv5te-none-eabi", - "thumbv6m-none-eabi", - "thumbv7em-none-eabi", - "thumbv7em-none-eabihf", - "thumbv7m-none-eabi", - "thumbv8m.base-none-eabi", - "thumbv8m.main-none-eabi", - "thumbv8m.main-none-eabihf", -]; - -#[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", - "riscv32imc-unknown-none-elf", -]; diff --git a/src/array_queue.rs b/src/array_queue.rs index e07fde8..3f6d195 100644 --- a/src/array_queue.rs +++ b/src/array_queue.rs @@ -6,7 +6,8 @@ use alloc::boxed::Box; use core::cell::UnsafeCell; use core::fmt; -use core::mem::MaybeUninit; +use core::mem::{self, MaybeUninit}; +use core::panic::{RefUnwindSafe, UnwindSafe}; use core::sync::atomic::{self, AtomicUsize, Ordering}; use crossbeam_utils::{Backoff, CachePadded}; @@ -76,6 +77,9 @@ pub struct ArrayQueue<T> { unsafe impl<T: Send> Sync for ArrayQueue<T> {} unsafe impl<T: Send> Send for ArrayQueue<T> {} +impl<T> UnwindSafe for ArrayQueue<T> {} +impl<T> RefUnwindSafe for ArrayQueue<T> {} + impl<T> ArrayQueue<T> { /// Creates a new bounded queue with the given capacity. /// @@ -443,37 +447,38 @@ impl<T> ArrayQueue<T> { impl<T> Drop for ArrayQueue<T> { fn drop(&mut self) { - // Get the index of the head. - let head = *self.head.get_mut(); - let tail = *self.tail.get_mut(); - - let hix = head & (self.one_lap - 1); - let tix = tail & (self.one_lap - 1); - - let len = if hix < tix { - tix - hix - } else if hix > tix { - self.cap - hix + tix - } else if tail == head { - 0 - } else { - self.cap - }; - - // Loop over all slots that hold a message and drop them. - for i in 0..len { - // Compute the index of the next slot holding a message. - let index = if hix + i < self.cap { - hix + i + if mem::needs_drop::<T>() { + // Get the index of the head. + let head = *self.head.get_mut(); + let tail = *self.tail.get_mut(); + + let hix = head & (self.one_lap - 1); + let tix = tail & (self.one_lap - 1); + + let len = if hix < tix { + tix - hix + } else if hix > tix { + self.cap - hix + tix + } else if tail == head { + 0 } else { - hix + i - self.cap + self.cap }; - unsafe { - debug_assert!(index < self.buffer.len()); - let slot = self.buffer.get_unchecked_mut(index); - let value = &mut *slot.value.get(); - value.as_mut_ptr().drop_in_place(); + // Loop over all slots that hold a message and drop them. + for i in 0..len { + // Compute the index of the next slot holding a message. + let index = if hix + i < self.cap { + hix + i + } else { + hix + i - self.cap + }; + + unsafe { + debug_assert!(index < self.buffer.len()); + let slot = self.buffer.get_unchecked_mut(index); + (*slot.value.get()).assume_init_drop(); + } } } } @@ -20,15 +20,13 @@ )] #![cfg_attr(not(feature = "std"), no_std)] -#[cfg(not(crossbeam_no_atomic_cas))] -cfg_if::cfg_if! { - if #[cfg(feature = "alloc")] { - extern crate alloc; +#[cfg(all(feature = "alloc", target_has_atomic = "ptr"))] +extern crate alloc; - mod array_queue; - mod seg_queue; +#[cfg(all(feature = "alloc", target_has_atomic = "ptr"))] +mod array_queue; +#[cfg(all(feature = "alloc", target_has_atomic = "ptr"))] +mod seg_queue; - pub use self::array_queue::ArrayQueue; - pub use self::seg_queue::SegQueue; - } -} +#[cfg(all(feature = "alloc", target_has_atomic = "ptr"))] +pub use crate::{array_queue::ArrayQueue, seg_queue::SegQueue}; diff --git a/src/seg_queue.rs b/src/seg_queue.rs index 2761dc0..973a77f 100644 --- a/src/seg_queue.rs +++ b/src/seg_queue.rs @@ -3,6 +3,7 @@ use core::cell::UnsafeCell; use core::fmt; use core::marker::PhantomData; use core::mem::MaybeUninit; +use core::panic::{RefUnwindSafe, UnwindSafe}; use core::ptr; use core::sync::atomic::{self, AtomicPtr, AtomicUsize, Ordering}; @@ -148,6 +149,9 @@ pub struct SegQueue<T> { unsafe impl<T: Send> Send for SegQueue<T> {} unsafe impl<T: Send> Sync for SegQueue<T> {} +impl<T> UnwindSafe for SegQueue<T> {} +impl<T> RefUnwindSafe for SegQueue<T> {} + impl<T> SegQueue<T> { /// Creates a new unbounded queue. /// @@ -455,8 +459,7 @@ impl<T> Drop for SegQueue<T> { if offset < BLOCK_CAP { // Drop the value in the slot. let slot = (*block).slots.get_unchecked(offset); - let p = &mut *slot.value.get(); - p.as_mut_ptr().drop_in_place(); + (*slot.value.get()).assume_init_drop(); } else { // Deallocate the block and move to the next one. let next = *(*block).next.get_mut(); @@ -521,8 +524,7 @@ impl<T> Iterator for IntoIter<T> { // and this is a non-empty queue. let item = unsafe { let slot = (*block).slots.get_unchecked(offset); - let p = &mut *slot.value.get(); - p.as_mut_ptr().read() + slot.value.get().read().assume_init() }; if offset + 1 == BLOCK_CAP { // Deallocate the block and move to the next one. |