Skip to content

Commit

Permalink
sync: make Notify panic safe (#5154)
Browse files Browse the repository at this point in the history
  • Loading branch information
attila-lin committed Nov 1, 2022
1 parent b1f40f4 commit 203a079
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tokio/src/sync/notify.rs
Expand Up @@ -13,6 +13,7 @@ use crate::util::WakeList;
use std::cell::UnsafeCell;
use std::future::Future;
use std::marker::PhantomPinned;
use std::panic::{RefUnwindSafe, UnwindSafe};
use std::pin::Pin;
use std::ptr::NonNull;
use std::sync::atomic::Ordering::SeqCst;
Expand Down Expand Up @@ -566,6 +567,9 @@ impl Default for Notify {
}
}

impl UnwindSafe for Notify {}
impl RefUnwindSafe for Notify {}

fn notify_locked(waiters: &mut WaitList, state: &AtomicUsize, curr: usize) -> Option<Waker> {
loop {
match get_state(curr) {
Expand Down
5 changes: 5 additions & 0 deletions tokio/tests/unwindsafe.rs
Expand Up @@ -3,6 +3,11 @@

use std::panic::{RefUnwindSafe, UnwindSafe};

#[test]
fn notify_is_unwind_safe() {
is_unwind_safe::<tokio::sync::Notify>();
}

#[test]
fn join_handle_is_unwind_safe() {
is_unwind_safe::<tokio::task::JoinHandle<()>>();
Expand Down

0 comments on commit 203a079

Please sign in to comment.