Skip to content

Commit 9bd6702

Browse files
authored
sync: mark mpsc types as UnwindSafe (#6783)
1 parent 365269a commit 9bd6702

File tree

6 files changed

+41
-3
lines changed

6 files changed

+41
-3
lines changed

tokio/src/loom/std/atomic_u16.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::cell::UnsafeCell;
22
use std::fmt;
33
use std::ops::Deref;
4+
use std::panic;
45

56
/// `AtomicU16` providing an additional `unsync_load` function.
67
pub(crate) struct AtomicU16 {
@@ -9,6 +10,8 @@ pub(crate) struct AtomicU16 {
910

1011
unsafe impl Send for AtomicU16 {}
1112
unsafe impl Sync for AtomicU16 {}
13+
impl panic::RefUnwindSafe for AtomicU16 {}
14+
impl panic::UnwindSafe for AtomicU16 {}
1215

1316
impl AtomicU16 {
1417
pub(crate) const fn new(val: u16) -> AtomicU16 {

tokio/src/loom/std/atomic_u32.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::cell::UnsafeCell;
22
use std::fmt;
33
use std::ops::Deref;
4+
use std::panic;
45

56
/// `AtomicU32` providing an additional `unsync_load` function.
67
pub(crate) struct AtomicU32 {
@@ -9,6 +10,8 @@ pub(crate) struct AtomicU32 {
910

1011
unsafe impl Send for AtomicU32 {}
1112
unsafe impl Sync for AtomicU32 {}
13+
impl panic::RefUnwindSafe for AtomicU32 {}
14+
impl panic::UnwindSafe for AtomicU32 {}
1215

1316
impl AtomicU32 {
1417
pub(crate) const fn new(val: u32) -> AtomicU32 {

tokio/src/loom/std/atomic_usize.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::cell::UnsafeCell;
22
use std::fmt;
33
use std::ops;
4+
use std::panic;
45

56
/// `AtomicUsize` providing an additional `unsync_load` function.
67
pub(crate) struct AtomicUsize {
@@ -9,6 +10,8 @@ pub(crate) struct AtomicUsize {
910

1011
unsafe impl Send for AtomicUsize {}
1112
unsafe impl Sync for AtomicUsize {}
13+
impl panic::RefUnwindSafe for AtomicUsize {}
14+
impl panic::UnwindSafe for AtomicUsize {}
1215

1316
impl AtomicUsize {
1417
pub(crate) const fn new(val: usize) -> AtomicUsize {

tokio/src/sync/mpsc/chan.rs

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use crate::sync::notify::Notify;
99
use crate::util::cacheline::CachePadded;
1010

1111
use std::fmt;
12+
use std::panic;
1213
use std::process;
1314
use std::sync::atomic::Ordering::{AcqRel, Acquire, Relaxed, Release};
1415
use std::task::Poll::{Pending, Ready};
@@ -108,6 +109,8 @@ impl<T> fmt::Debug for RxFields<T> {
108109

109110
unsafe impl<T: Send, S: Send> Send for Chan<T, S> {}
110111
unsafe impl<T: Send, S: Sync> Sync for Chan<T, S> {}
112+
impl<T, S> panic::RefUnwindSafe for Chan<T, S> {}
113+
impl<T, S> panic::UnwindSafe for Chan<T, S> {}
111114

112115
pub(crate) fn channel<T, S: Semaphore>(semaphore: S) -> (Tx<T, S>, Rx<T, S>) {
113116
let (tx, rx) = list::channel();

tokio/tests/async_send_sync.rs

+6
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,12 @@ assert_value!(tokio::sync::mpsc::UnboundedReceiver<YY>: Send & Sync & Unpin);
413413
assert_value!(tokio::sync::mpsc::UnboundedSender<NN>: !Send & !Sync & Unpin);
414414
assert_value!(tokio::sync::mpsc::UnboundedSender<YN>: Send & Sync & Unpin);
415415
assert_value!(tokio::sync::mpsc::UnboundedSender<YY>: Send & Sync & Unpin);
416+
assert_value!(tokio::sync::mpsc::WeakSender<NN>: !Send & !Sync & Unpin);
417+
assert_value!(tokio::sync::mpsc::WeakSender<YN>: Send & Sync & Unpin);
418+
assert_value!(tokio::sync::mpsc::WeakSender<YY>: Send & Sync & Unpin);
419+
assert_value!(tokio::sync::mpsc::WeakUnboundedSender<NN>: !Send & !Sync & Unpin);
420+
assert_value!(tokio::sync::mpsc::WeakUnboundedSender<YN>: Send & Sync & Unpin);
421+
assert_value!(tokio::sync::mpsc::WeakUnboundedSender<YY>: Send & Sync & Unpin);
416422
assert_value!(tokio::sync::mpsc::error::SendError<NN>: !Send & !Sync & Unpin);
417423
assert_value!(tokio::sync::mpsc::error::SendError<YN>: Send & !Sync & Unpin);
418424
assert_value!(tokio::sync::mpsc::error::SendError<YY>: Send & Sync & Unpin);

tokio/tests/sync_mpsc.rs

+23-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use wasm_bindgen_test::wasm_bindgen_test as maybe_tokio_test;
1111
use tokio::test as maybe_tokio_test;
1212

1313
use std::fmt;
14+
use std::panic;
1415
use std::sync::Arc;
1516
use tokio::sync::mpsc;
1617
use tokio::sync::mpsc::error::{TryRecvError, TrySendError};
@@ -22,9 +23,28 @@ mod support {
2223
}
2324

2425
#[allow(unused)]
25-
trait AssertSend: Send {}
26-
impl AssertSend for mpsc::Sender<i32> {}
27-
impl AssertSend for mpsc::Receiver<i32> {}
26+
trait AssertRefUnwindSafe: panic::RefUnwindSafe {}
27+
impl<T> AssertRefUnwindSafe for mpsc::OwnedPermit<T> {}
28+
impl<'a, T> AssertRefUnwindSafe for mpsc::Permit<'a, T> {}
29+
impl<'a, T> AssertRefUnwindSafe for mpsc::PermitIterator<'a, T> {}
30+
impl<T> AssertRefUnwindSafe for mpsc::Receiver<T> {}
31+
impl<T> AssertRefUnwindSafe for mpsc::Sender<T> {}
32+
impl<T> AssertRefUnwindSafe for mpsc::UnboundedReceiver<T> {}
33+
impl<T> AssertRefUnwindSafe for mpsc::UnboundedSender<T> {}
34+
impl<T> AssertRefUnwindSafe for mpsc::WeakSender<T> {}
35+
impl<T> AssertRefUnwindSafe for mpsc::WeakUnboundedSender<T> {}
36+
37+
#[allow(unused)]
38+
trait AssertUnwindSafe: panic::UnwindSafe {}
39+
impl<T> AssertUnwindSafe for mpsc::OwnedPermit<T> {}
40+
impl<'a, T> AssertUnwindSafe for mpsc::Permit<'a, T> {}
41+
impl<'a, T> AssertUnwindSafe for mpsc::PermitIterator<'a, T> {}
42+
impl<T> AssertUnwindSafe for mpsc::Receiver<T> {}
43+
impl<T> AssertUnwindSafe for mpsc::Sender<T> {}
44+
impl<T> AssertUnwindSafe for mpsc::UnboundedReceiver<T> {}
45+
impl<T> AssertUnwindSafe for mpsc::UnboundedSender<T> {}
46+
impl<T> AssertUnwindSafe for mpsc::WeakSender<T> {}
47+
impl<T> AssertUnwindSafe for mpsc::WeakUnboundedSender<T> {}
2848

2949
#[maybe_tokio_test]
3050
async fn send_recv_with_buffer() {

0 commit comments

Comments
 (0)