Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark some more types as UnwindSafe #6783

Merged
merged 3 commits into from
Aug 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions tokio/src/loom/std/atomic_u16.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::cell::UnsafeCell;
use std::fmt;
use std::ops::Deref;
use std::panic;

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

unsafe impl Send for AtomicU16 {}
unsafe impl Sync for AtomicU16 {}
impl panic::RefUnwindSafe for AtomicU16 {}
impl panic::UnwindSafe for AtomicU16 {}

impl AtomicU16 {
pub(crate) const fn new(val: u16) -> AtomicU16 {
Expand Down
3 changes: 3 additions & 0 deletions tokio/src/loom/std/atomic_u32.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::cell::UnsafeCell;
use std::fmt;
use std::ops::Deref;
use std::panic;

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

unsafe impl Send for AtomicU32 {}
unsafe impl Sync for AtomicU32 {}
impl panic::RefUnwindSafe for AtomicU32 {}
impl panic::UnwindSafe for AtomicU32 {}

impl AtomicU32 {
pub(crate) const fn new(val: u32) -> AtomicU32 {
Expand Down
3 changes: 3 additions & 0 deletions tokio/src/loom/std/atomic_usize.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::cell::UnsafeCell;
use std::fmt;
use std::ops;
use std::panic;

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

unsafe impl Send for AtomicUsize {}
unsafe impl Sync for AtomicUsize {}
impl panic::RefUnwindSafe for AtomicUsize {}
impl panic::UnwindSafe for AtomicUsize {}

impl AtomicUsize {
pub(crate) const fn new(val: usize) -> AtomicUsize {
Expand Down
3 changes: 3 additions & 0 deletions tokio/src/sync/mpsc/chan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::sync::notify::Notify;
use crate::util::cacheline::CachePadded;

use std::fmt;
use std::panic;
use std::process;
use std::sync::atomic::Ordering::{AcqRel, Acquire, Relaxed, Release};
use std::task::Poll::{Pending, Ready};
Expand Down Expand Up @@ -108,6 +109,8 @@ impl<T> fmt::Debug for RxFields<T> {

unsafe impl<T: Send, S: Send> Send for Chan<T, S> {}
unsafe impl<T: Send, S: Sync> Sync for Chan<T, S> {}
impl<T, S> panic::RefUnwindSafe for Chan<T, S> {}
impl<T, S> panic::UnwindSafe for Chan<T, S> {}

pub(crate) fn channel<T, S: Semaphore>(semaphore: S) -> (Tx<T, S>, Rx<T, S>) {
let (tx, rx) = list::channel();
Expand Down
6 changes: 6 additions & 0 deletions tokio/tests/async_send_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,12 @@ assert_value!(tokio::sync::mpsc::UnboundedReceiver<YY>: Send & Sync & Unpin);
assert_value!(tokio::sync::mpsc::UnboundedSender<NN>: !Send & !Sync & Unpin);
assert_value!(tokio::sync::mpsc::UnboundedSender<YN>: Send & Sync & Unpin);
assert_value!(tokio::sync::mpsc::UnboundedSender<YY>: Send & Sync & Unpin);
assert_value!(tokio::sync::mpsc::WeakSender<NN>: !Send & !Sync & Unpin);
assert_value!(tokio::sync::mpsc::WeakSender<YN>: Send & Sync & Unpin);
assert_value!(tokio::sync::mpsc::WeakSender<YY>: Send & Sync & Unpin);
assert_value!(tokio::sync::mpsc::WeakUnboundedSender<NN>: !Send & !Sync & Unpin);
assert_value!(tokio::sync::mpsc::WeakUnboundedSender<YN>: Send & Sync & Unpin);
assert_value!(tokio::sync::mpsc::WeakUnboundedSender<YY>: Send & Sync & Unpin);
assert_value!(tokio::sync::mpsc::error::SendError<NN>: !Send & !Sync & Unpin);
assert_value!(tokio::sync::mpsc::error::SendError<YN>: Send & !Sync & Unpin);
assert_value!(tokio::sync::mpsc::error::SendError<YY>: Send & Sync & Unpin);
Expand Down
26 changes: 23 additions & 3 deletions tokio/tests/sync_mpsc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use wasm_bindgen_test::wasm_bindgen_test as maybe_tokio_test;
use tokio::test as maybe_tokio_test;

use std::fmt;
use std::panic;
use std::sync::Arc;
use tokio::sync::mpsc;
use tokio::sync::mpsc::error::{TryRecvError, TrySendError};
Expand All @@ -22,9 +23,28 @@ mod support {
}

#[allow(unused)]
trait AssertSend: Send {}
impl AssertSend for mpsc::Sender<i32> {}
impl AssertSend for mpsc::Receiver<i32> {}
trait AssertRefUnwindSafe: panic::RefUnwindSafe {}
impl<T> AssertRefUnwindSafe for mpsc::OwnedPermit<T> {}
impl<'a, T> AssertRefUnwindSafe for mpsc::Permit<'a, T> {}
impl<'a, T> AssertRefUnwindSafe for mpsc::PermitIterator<'a, T> {}
impl<T> AssertRefUnwindSafe for mpsc::Receiver<T> {}
impl<T> AssertRefUnwindSafe for mpsc::Sender<T> {}
impl<T> AssertRefUnwindSafe for mpsc::UnboundedReceiver<T> {}
impl<T> AssertRefUnwindSafe for mpsc::UnboundedSender<T> {}
impl<T> AssertRefUnwindSafe for mpsc::WeakSender<T> {}
impl<T> AssertRefUnwindSafe for mpsc::WeakUnboundedSender<T> {}

#[allow(unused)]
trait AssertUnwindSafe: panic::UnwindSafe {}
impl<T> AssertUnwindSafe for mpsc::OwnedPermit<T> {}
impl<'a, T> AssertUnwindSafe for mpsc::Permit<'a, T> {}
impl<'a, T> AssertUnwindSafe for mpsc::PermitIterator<'a, T> {}
impl<T> AssertUnwindSafe for mpsc::Receiver<T> {}
impl<T> AssertUnwindSafe for mpsc::Sender<T> {}
impl<T> AssertUnwindSafe for mpsc::UnboundedReceiver<T> {}
impl<T> AssertUnwindSafe for mpsc::UnboundedSender<T> {}
impl<T> AssertUnwindSafe for mpsc::WeakSender<T> {}
impl<T> AssertUnwindSafe for mpsc::WeakUnboundedSender<T> {}

#[maybe_tokio_test]
async fn send_recv_with_buffer() {
Expand Down
Loading