Skip to content

Commit

Permalink
Merge #964
Browse files Browse the repository at this point in the history
964: v0.8: Prepare for the next release r=taiki-e a=taiki-e

Changes:
- crossbeam-channel 0.5.6 -> 0.5.7
  - Improve handling of very large timeout. (#953)
- crossbeam-deque 0.8.2 -> 0.8.3
  - Add `Stealer::{steal_batch_with_limit, steal_batch_with_limit_and_pop}` methods. (#903)
  - Add `Injector::{steal_batch_with_limit, steal_batch_with_limit_and_pop}` methods. (#903)
- crossbeam-epoch 0.9.13 -> 0.9.14
  - Update `memoffset` to 0.8. (#955)
- crossbeam-utils 0.8.14 -> 0.8.15
  - Add `#[clippy::has_significant_drop]` to `ShardedLock{Read,Write}Guard`. (#958)
  - Improve handling of very large timeout. (#953)
  - Soft-deprecate `thread::scope()` in favor of the more efficient `std::thread::scope` that stabilized on Rust 1.63. (#954)

Backports:
- #903
- #936
- #953
- #954
- #955
- #958

Co-authored-by: glorv <glorvs@163.com>
Co-authored-by: Taiki Endo <te316e89@gmail.com>
Co-authored-by: Alexis (Poliorcetics) Bourget <alexis.bourget@gmail.com>
Co-authored-by: Caio <c410.f3r@gmail.com>
  • Loading branch information
5 people authored Feb 28, 2023
2 parents 366276a + 018ef4e commit 4778b46
Show file tree
Hide file tree
Showing 20 changed files with 237 additions and 45 deletions.
5 changes: 5 additions & 0 deletions ci/no_atomic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ for target in $(rustc --print target-list); do
res=$(jq <<<"${target_spec}" -r 'select(."atomic-cas" == false)')
[[ -z "${res}" ]] || no_atomic_cas+=("${target}")
max_atomic_width=$(jq <<<"${target_spec}" -r '."max-atomic-width"')
min_atomic_width=$(jq <<<"${target_spec}" -r '."min-atomic-width"')
case "${max_atomic_width}" in
# It is not clear exactly what `"max-atomic-width" == null` means, but they
# actually seem to have the same max-atomic-width as the target-pointer-width.
Expand All @@ -35,6 +36,10 @@ for target in $(rustc --print target-list); do
# There is no `"max-atomic-width" == 16` or `"max-atomic-width" == 8` targets.
*) exit 1 ;;
esac
case "${min_atomic_width}" in
8 | null) ;;
*) no_atomic+=("${target}") ;;
esac
done

cat >"${file}" <<EOF
Expand Down
4 changes: 4 additions & 0 deletions crossbeam-channel/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion crossbeam-channel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
28 changes: 21 additions & 7 deletions crossbeam-channel/src/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down Expand Up @@ -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(),
}
}

Expand Down Expand Up @@ -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(),
}
}

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
7 changes: 1 addition & 6 deletions crossbeam-channel/src/flavors/at.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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]
Expand Down
5 changes: 2 additions & 3 deletions crossbeam-channel/src/flavors/tick.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
Expand All @@ -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,
}
}
Expand Down
10 changes: 8 additions & 2 deletions crossbeam-channel/src/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 0 additions & 8 deletions crossbeam-channel/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}
5 changes: 5 additions & 0 deletions crossbeam-deque/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Version 0.8.3

- Add `Stealer::{steal_batch_with_limit, steal_batch_with_limit_and_pop}` methods. (#903)
- Add `Injector::{steal_batch_with_limit, steal_batch_with_limit_and_pop}` methods. (#903)

# Version 0.8.2

- Bump the minimum supported Rust version to 1.38. (#877)
Expand Down
2 changes: 1 addition & 1 deletion crossbeam-deque/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name = "crossbeam-deque"
# - Update CHANGELOG.md
# - Update README.md
# - Create "crossbeam-deque-X.Y.Z" git tag
version = "0.8.2"
version = "0.8.3"
edition = "2018"
rust-version = "1.38"
license = "MIT OR Apache-2.0"
Expand Down
Loading

0 comments on commit 4778b46

Please sign in to comment.