diff options
author | Jeff Vander Stoep <jeffv@google.com> | 2023-03-06 11:21:29 +0100 |
---|---|---|
committer | Jeff Vander Stoep <jeffv@google.com> | 2023-03-06 11:21:29 +0100 |
commit | 15b40a1709878953d393bf88c8c6a74dcb971b29 (patch) | |
tree | b6a285217017d83e7f81379b282b8f2d25454899 | |
parent | 4877d95cd659ea64242683ee6ffc5ab9282149c0 (diff) | |
download | crossbeam-channel-15b40a1709878953d393bf88c8c6a74dcb971b29.tar.gz |
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
-rw-r--r-- | .cargo_vcs_info.json | 2 | ||||
-rw-r--r-- | Android.bp | 2 | ||||
-rw-r--r-- | CHANGELOG.md | 4 | ||||
-rw-r--r-- | Cargo.lock (renamed from Cargo.lock.saved) | 45 | ||||
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | Cargo.toml.orig | 2 | ||||
-rw-r--r-- | METADATA | 10 | ||||
-rw-r--r-- | src/channel.rs | 30 | ||||
-rw-r--r-- | src/flavors/at.rs | 7 | ||||
-rw-r--r-- | src/flavors/tick.rs | 5 | ||||
-rw-r--r-- | src/select.rs | 10 | ||||
-rw-r--r-- | src/utils.rs | 8 | ||||
-rw-r--r-- | tests/golang.rs | 2 | ||||
-rw-r--r-- | tests/ready.rs | 1 |
14 files changed, 67 insertions, 63 deletions
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 @@ -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.saved b/Cargo.lock index e40f836..e4b10f4 100644 --- a/Cargo.lock.saved +++ b/Cargo.lock @@ -10,7 +10,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "crossbeam-channel" -version = "0.5.6" +version = "0.5.7" dependencies = [ "cfg-if", "crossbeam-utils", @@ -21,19 +21,18 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.11" +version = "0.8.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51887d4adc7b564537b15adcfb307936f8075dfcd5f00dde9a9f1d29383682bc" +checksum = "3c063cd8cc95f5c377ed0d4b49a4b21f632396ff690e8470c29b3359b346984b" dependencies = [ "cfg-if", - "once_cell", ] [[package]] name = "getrandom" -version = "0.2.7" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6" +checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" dependencies = [ "cfg-if", "libc", @@ -42,40 +41,34 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.1.19" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" dependencies = [ "libc", ] [[package]] name = "libc" -version = "0.2.126" +version = "0.2.139" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" +checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" [[package]] name = "num_cpus" -version = "1.13.1" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1" +checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" 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" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "rand" @@ -100,18 +93,18 @@ dependencies = [ [[package]] name = "rand_core" -version = "0.6.3" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ "getrandom", ] [[package]] name = "signal-hook" -version = "0.3.14" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a253b5e89e2698464fc26b545c9edceb338e18a89effeeecfea192c3025be29d" +checksum = "732768f1176d21d09e076c23a93123d40bba92d50c4058da34d45c8de8e682b9" dependencies = [ "libc", "signal-hook-registry", @@ -119,9 +112,9 @@ dependencies = [ [[package]] name = "signal-hook-registry" -version = "1.4.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51e73328dc4ac0c7ccbda3a494dfa03df1de2f46018127f60c693f2648455b0" +checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" dependencies = [ "libc", ] @@ -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" @@ -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<T>(cap: usize) -> (Sender<T>, Receiver<T>) { /// 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<T>(cap: usize) -> (Sender<T>, Receiver<T>) { /// assert!(eq(Instant::now(), start + ms(500))); /// ``` pub fn after(duration: Duration) -> Receiver<Instant> { - 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<T>() -> Receiver<T> { /// assert!(eq(Instant::now(), start + ms(700))); /// ``` pub fn tick(duration: Duration) -> Receiver<Instant> { - 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<T> Sender<T> { /// ); /// ``` pub fn send_timeout(&self, msg: T, timeout: Duration) -> Result<(), SendTimeoutError<T>> { - 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<T> Receiver<T> { /// ); /// ``` pub fn recv_timeout(&self, timeout: Duration) -> Result<T, RecvTimeoutError> { - 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<Instant>; @@ -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<SelectedOperation<'a>, 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<usize, ReadyTimeoutError> { - 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<Instant>) { } } } - -// 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(); |