mirror of
https://github.com/tokio-rs/tokio.git
synced 2025-09-28 12:10:37 +00:00
sync: mark mpsc types as UnwindSafe
(#6783)
This commit is contained in:
parent
365269adaf
commit
9bd6702a3f
@ -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 {
|
||||
@ -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 {
|
||||
|
@ -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 {
|
||||
@ -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 {
|
||||
|
@ -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 {
|
||||
@ -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 {
|
||||
|
@ -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};
|
||||
@ -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();
|
||||
|
@ -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);
|
||||
|
@ -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};
|
||||
@ -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() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user