From 15b40a1709878953d393bf88c8c6a74dcb971b29 Mon Sep 17 00:00:00 2001 From: Jeff Vander Stoep Date: Mon, 6 Mar 2023 11:21:29 +0100 Subject: Upgrade crossbeam-channel to 0.5.7 This project was upgraded with external_updater. Usage: tools/external_updater/updater.sh update rust/crates/crossbeam-channel For more info, check https://cs.android.com/android/platform/superproject/+/master:tools/external_updater/README.md Test: TreeHugger Change-Id: Ie5f0a41496c51cf52ce2eb662d07ef5d84d6a607 --- .cargo_vcs_info.json | 2 +- Android.bp | 2 +- CHANGELOG.md | 4 ++ Cargo.lock | 126 ++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.lock.saved | 133 --------------------------------------------------- Cargo.toml | 2 +- Cargo.toml.orig | 2 +- METADATA | 10 ++-- src/channel.rs | 30 ++++++++---- src/flavors/at.rs | 7 +-- src/flavors/tick.rs | 5 +- src/select.rs | 10 +++- src/utils.rs | 8 ---- tests/golang.rs | 2 +- tests/ready.rs | 1 + 15 files changed, 174 insertions(+), 170 deletions(-) create mode 100644 Cargo.lock delete mode 100644 Cargo.lock.saved diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index d38e4ea..548f675 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,6 +1,6 @@ { "git": { - "sha1": "5e0f59a9990c032c33e1db16a6bfc64b4ab6102d" + "sha1": "721382b00b5dadd81954ed66764d547e2f1bb7a3" }, "path_in_vcs": "crossbeam-channel" } \ No newline at end of file diff --git a/Android.bp b/Android.bp index e9f9698..6af581d 100644 --- a/Android.bp +++ b/Android.bp @@ -47,7 +47,7 @@ rust_library { host_supported: true, crate_name: "crossbeam_channel", cargo_env_compat: true, - cargo_pkg_version: "0.5.6", + cargo_pkg_version: "0.5.7", srcs: ["src/lib.rs"], edition: "2018", features: [ diff --git a/CHANGELOG.md b/CHANGELOG.md index f0d11e6..3277f15 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# Version 0.5.7 + +- Improve handling of very large timeout. (#953) + # Version 0.5.6 - Bump the minimum supported Rust version to 1.38. (#877) diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..e4b10f4 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,126 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "crossbeam-channel" +version = "0.5.7" +dependencies = [ + "cfg-if", + "crossbeam-utils", + "num_cpus", + "rand", + "signal-hook", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c063cd8cc95f5c377ed0d4b49a4b21f632396ff690e8470c29b3359b346984b" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "getrandom" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "hermit-abi" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" +dependencies = [ + "libc", +] + +[[package]] +name = "libc" +version = "0.2.139" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" + +[[package]] +name = "num_cpus" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "signal-hook" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "732768f1176d21d09e076c23a93123d40bba92d50c4058da34d45c8de8e682b9" +dependencies = [ + "libc", + "signal-hook-registry", +] + +[[package]] +name = "signal-hook-registry" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" +dependencies = [ + "libc", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" diff --git a/Cargo.lock.saved b/Cargo.lock.saved deleted file mode 100644 index e40f836..0000000 --- a/Cargo.lock.saved +++ /dev/null @@ -1,133 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "crossbeam-channel" -version = "0.5.6" -dependencies = [ - "cfg-if", - "crossbeam-utils", - "num_cpus", - "rand", - "signal-hook", -] - -[[package]] -name = "crossbeam-utils" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51887d4adc7b564537b15adcfb307936f8075dfcd5f00dde9a9f1d29383682bc" -dependencies = [ - "cfg-if", - "once_cell", -] - -[[package]] -name = "getrandom" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6" -dependencies = [ - "cfg-if", - "libc", - "wasi", -] - -[[package]] -name = "hermit-abi" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" -dependencies = [ - "libc", -] - -[[package]] -name = "libc" -version = "0.2.126" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" - -[[package]] -name = "num_cpus" -version = "1.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1" -dependencies = [ - "hermit-abi", - "libc", -] - -[[package]] -name = "once_cell" -version = "1.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1" - -[[package]] -name = "ppv-lite86" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" - -[[package]] -name = "rand" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" -dependencies = [ - "libc", - "rand_chacha", - "rand_core", -] - -[[package]] -name = "rand_chacha" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" -dependencies = [ - "ppv-lite86", - "rand_core", -] - -[[package]] -name = "rand_core" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" -dependencies = [ - "getrandom", -] - -[[package]] -name = "signal-hook" -version = "0.3.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a253b5e89e2698464fc26b545c9edceb338e18a89effeeecfea192c3025be29d" -dependencies = [ - "libc", - "signal-hook-registry", -] - -[[package]] -name = "signal-hook-registry" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51e73328dc4ac0c7ccbda3a494dfa03df1de2f46018127f60c693f2648455b0" -dependencies = [ - "libc", -] - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" diff --git a/Cargo.toml b/Cargo.toml index 619fad4..b0e95c3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,7 @@ edition = "2018" rust-version = "1.38" name = "crossbeam-channel" -version = "0.5.6" +version = "0.5.7" description = "Multi-producer multi-consumer channels for message passing" homepage = "https://github.com/crossbeam-rs/crossbeam/tree/master/crossbeam-channel" readme = "README.md" diff --git a/Cargo.toml.orig b/Cargo.toml.orig index 8089202..25c3678 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -4,7 +4,7 @@ name = "crossbeam-channel" # - Update CHANGELOG.md # - Update README.md # - Create "crossbeam-channel-X.Y.Z" git tag -version = "0.5.6" +version = "0.5.7" edition = "2018" rust-version = "1.38" license = "MIT OR Apache-2.0" diff --git a/METADATA b/METADATA index d482420..d824734 100644 --- a/METADATA +++ b/METADATA @@ -11,13 +11,13 @@ third_party { } url { type: ARCHIVE - value: "https://static.crates.io/crates/crossbeam-channel/crossbeam-channel-0.5.6.crate" + value: "https://static.crates.io/crates/crossbeam-channel/crossbeam-channel-0.5.7.crate" } - version: "0.5.6" + version: "0.5.7" license_type: NOTICE last_upgrade_date { - year: 2022 - month: 12 - day: 8 + year: 2023 + month: 3 + day: 6 } } diff --git a/src/channel.rs b/src/channel.rs index 800fe63..bd24115 100644 --- a/src/channel.rs +++ b/src/channel.rs @@ -14,7 +14,6 @@ use crate::err::{ }; use crate::flavors; use crate::select::{Operation, SelectHandle, Token}; -use crate::utils; /// Creates a channel of unbounded capacity. /// @@ -160,7 +159,7 @@ pub fn bounded(cap: usize) -> (Sender, Receiver) { /// let ms = |ms| Duration::from_millis(ms); /// /// // Returns `true` if `a` and `b` are very close `Instant`s. -/// let eq = |a, b| a + ms(50) > b && b + ms(50) > a; +/// let eq = |a, b| a + ms(60) > b && b + ms(60) > a; /// /// let start = Instant::now(); /// let r = after(ms(100)); @@ -172,8 +171,11 @@ pub fn bounded(cap: usize) -> (Sender, Receiver) { /// assert!(eq(Instant::now(), start + ms(500))); /// ``` pub fn after(duration: Duration) -> Receiver { - Receiver { - flavor: ReceiverFlavor::At(Arc::new(flavors::at::Channel::new_timeout(duration))), + match Instant::now().checked_add(duration) { + Some(deadline) => Receiver { + flavor: ReceiverFlavor::At(Arc::new(flavors::at::Channel::new_deadline(deadline))), + }, + None => never(), } } @@ -320,8 +322,14 @@ pub fn never() -> Receiver { /// assert!(eq(Instant::now(), start + ms(700))); /// ``` pub fn tick(duration: Duration) -> Receiver { - Receiver { - flavor: ReceiverFlavor::Tick(Arc::new(flavors::tick::Channel::new(duration))), + match Instant::now().checked_add(duration) { + Some(delivery_time) => Receiver { + flavor: ReceiverFlavor::Tick(Arc::new(flavors::tick::Channel::new( + delivery_time, + duration, + ))), + }, + None => never(), } } @@ -474,7 +482,10 @@ impl Sender { /// ); /// ``` pub fn send_timeout(&self, msg: T, timeout: Duration) -> Result<(), SendTimeoutError> { - self.send_deadline(msg, utils::convert_timeout_to_deadline(timeout)) + match Instant::now().checked_add(timeout) { + Some(deadline) => self.send_deadline(msg, deadline), + None => self.send(msg).map_err(SendTimeoutError::from), + } } /// Waits for a message to be sent into the channel, but only until a given deadline. @@ -864,7 +875,10 @@ impl Receiver { /// ); /// ``` pub fn recv_timeout(&self, timeout: Duration) -> Result { - self.recv_deadline(utils::convert_timeout_to_deadline(timeout)) + match Instant::now().checked_add(timeout) { + Some(deadline) => self.recv_deadline(deadline), + None => self.recv().map_err(RecvTimeoutError::from), + } } /// Waits for a message to be received from the channel, but only before a given deadline. diff --git a/src/flavors/at.rs b/src/flavors/at.rs index ca5ee60..515c4e3 100644 --- a/src/flavors/at.rs +++ b/src/flavors/at.rs @@ -4,7 +4,7 @@ use std::sync::atomic::{AtomicBool, Ordering}; use std::thread; -use std::time::{Duration, Instant}; +use std::time::Instant; use crate::context::Context; use crate::err::{RecvTimeoutError, TryRecvError}; @@ -32,11 +32,6 @@ impl Channel { received: AtomicBool::new(false), } } - /// Creates a channel that delivers a message after a certain duration of time. - #[inline] - pub(crate) fn new_timeout(dur: Duration) -> Self { - Self::new_deadline(utils::convert_timeout_to_deadline(dur)) - } /// Attempts to receive a message without blocking. #[inline] diff --git a/src/flavors/tick.rs b/src/flavors/tick.rs index 4201b6e..d38f6a5 100644 --- a/src/flavors/tick.rs +++ b/src/flavors/tick.rs @@ -10,7 +10,6 @@ use crossbeam_utils::atomic::AtomicCell; use crate::context::Context; use crate::err::{RecvTimeoutError, TryRecvError}; use crate::select::{Operation, SelectHandle, Token}; -use crate::utils; /// Result of a receive operation. pub(crate) type TickToken = Option; @@ -27,9 +26,9 @@ pub(crate) struct Channel { impl Channel { /// Creates a channel that delivers messages periodically. #[inline] - pub(crate) fn new(dur: Duration) -> Self { + pub(crate) fn new(delivery_time: Instant, dur: Duration) -> Self { Channel { - delivery_time: AtomicCell::new(utils::convert_timeout_to_deadline(dur)), + delivery_time: AtomicCell::new(delivery_time), duration: dur, } } diff --git a/src/select.rs b/src/select.rs index 57d67a3..3eb0b97 100644 --- a/src/select.rs +++ b/src/select.rs @@ -487,7 +487,10 @@ pub fn select_timeout<'a>( handles: &mut [(&'a dyn SelectHandle, usize, *const u8)], timeout: Duration, ) -> Result, SelectTimeoutError> { - select_deadline(handles, utils::convert_timeout_to_deadline(timeout)) + match Instant::now().checked_add(timeout) { + Some(deadline) => select_deadline(handles, deadline), + None => Ok(select(handles)), + } } /// Blocks until a given deadline, or until one of the operations becomes ready and selects it. @@ -1045,7 +1048,10 @@ impl<'a> Select<'a> { /// } /// ``` pub fn ready_timeout(&mut self, timeout: Duration) -> Result { - self.ready_deadline(utils::convert_timeout_to_deadline(timeout)) + match Instant::now().checked_add(timeout) { + Some(deadline) => self.ready_deadline(deadline), + None => Ok(self.ready()), + } } /// Blocks until a given deadline, or until one of the operations becomes ready. diff --git a/src/utils.rs b/src/utils.rs index 9f14c8e..f623f27 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -56,11 +56,3 @@ pub(crate) fn sleep_until(deadline: Option) { } } } - -// https://github.com/crossbeam-rs/crossbeam/issues/795 -pub(crate) fn convert_timeout_to_deadline(timeout: Duration) -> Instant { - match Instant::now().checked_add(timeout) { - Some(deadline) => deadline, - None => Instant::now() + Duration::from_secs(86400 * 365 * 30), - } -} diff --git a/tests/golang.rs b/tests/golang.rs index 8050716..41149f4 100644 --- a/tests/golang.rs +++ b/tests/golang.rs @@ -9,7 +9,7 @@ //! - https://golang.org/LICENSE //! - https://golang.org/PATENTS -#![allow(clippy::mutex_atomic, clippy::redundant_clone)] +#![allow(clippy::redundant_clone)] use std::alloc::{GlobalAlloc, Layout, System}; use std::any::Any; diff --git a/tests/ready.rs b/tests/ready.rs index d8dd6ce..6e3fb2b 100644 --- a/tests/ready.rs +++ b/tests/ready.rs @@ -229,6 +229,7 @@ fn default_when_disconnected() { } #[test] +#[cfg_attr(miri, ignore)] // this test makes timing assumptions, but Miri is so slow it violates them fn default_only() { let start = Instant::now(); -- cgit v1.2.3