Skip to content
Open
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
32 changes: 32 additions & 0 deletions tokio/src/loom/std/parking_lot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use std::fmt;
use std::marker::PhantomData;
use std::ops::{Deref, DerefMut};
use std::panic;
use std::sync::LockResult;
use std::time::Duration;

Expand Down Expand Up @@ -45,6 +46,37 @@ pub(crate) struct RwLockWriteGuard<'a, T: ?Sized>(
parking_lot::RwLockWriteGuard<'a, T>,
);

// `UnwindSafe` and `RefUnwindSafe` traits have been
// adjusted to match values from std for wrapped types.
//
// See <https://github.com/tokio-rs/tokio/pull/7487> for more info.

// parking_lot's `Mutex` is UnwindSafe and !RefUnwindSafe
// std's `Mutex` is UnwindSafe and RefUnwindSafe
impl<T: ?Sized> panic::RefUnwindSafe for Mutex<T> {}

// parking_lot's `MutexGuard` is !UnwindSafe and !RefUnwindSafe
// std's `MutexGuard` is UnwindSafe and RefUnwindSafe
impl<T: ?Sized> panic::UnwindSafe for MutexGuard<'_, T> {}
impl<T: ?Sized> panic::RefUnwindSafe for MutexGuard<'_, T> {}

// parking_lot's `RwLock` is UnwindSafe and !RefUnwindSafe
// std's `RwLock` is UnwindSafe and RefUnwindSafe
impl<T> panic::RefUnwindSafe for RwLock<T> {}

// parking_lot's `RwLockReadGuard` is !UnwindSafe and !RefUnwindSafe
// std's `RwLockReadGuard` is UnwindSafe and RefUnwindSafe
impl<T: ?Sized> panic::UnwindSafe for RwLockReadGuard<'_, T> {}
impl<T: ?Sized> panic::RefUnwindSafe for RwLockReadGuard<'_, T> {}

// parking_lot's `RwLockWriteGuard` is !UnwindSafe and !RefUnwindSafe
// std's `RwLockWriteGuard` is UnwindSafe and RefUnwindSafe
impl<T: ?Sized> panic::UnwindSafe for RwLockWriteGuard<'_, T> {}
impl<T: ?Sized> panic::RefUnwindSafe for RwLockWriteGuard<'_, T> {}

// parking_lot's `Condvar` is UnwindSafe and RefUnwindSafe
// std's `Condwar` is UnwindSafe and RefUnwindSafe

impl<T> Mutex<T> {
#[inline]
pub(crate) fn new(t: T) -> Mutex<T> {
Expand Down
2 changes: 2 additions & 0 deletions tokio/src/util/linked_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use core::fmt;
use core::marker::{PhantomData, PhantomPinned};
use core::mem::ManuallyDrop;
use core::ptr::{self, NonNull};
use std::panic::UnwindSafe;

/// An intrusive linked list.
///
Expand All @@ -29,6 +30,7 @@ pub(crate) struct LinkedList<L, T> {

unsafe impl<L: Link> Send for LinkedList<L, L::Target> where L::Target: Send {}
unsafe impl<L: Link> Sync for LinkedList<L, L::Target> where L::Target: Sync {}
impl<L: Link> UnwindSafe for LinkedList<L, L::Target> {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the linked list is just raw pointers, having manual impls for both traits is probably the right call.


/// Defines how a type is tracked within a linked list.
///
Expand Down
Loading
Loading