From 07b26c242b705b044d59af6a858edd36a1cdc3b1 Mon Sep 17 00:00:00 2001 From: hzlinyiyu Date: Tue, 1 Nov 2022 19:40:19 +0800 Subject: [PATCH] sync: make Notify panic safe --- tokio/src/sync/notify.rs | 4 ++++ tokio/tests/unwindsafe.rs | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/tokio/src/sync/notify.rs b/tokio/src/sync/notify.rs index 83bd6823694..efe16f9f8ef 100644 --- a/tokio/src/sync/notify.rs +++ b/tokio/src/sync/notify.rs @@ -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; @@ -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 { loop { match get_state(curr) { diff --git a/tokio/tests/unwindsafe.rs b/tokio/tests/unwindsafe.rs index 98cf5b1b044..3e63820864d 100644 --- a/tokio/tests/unwindsafe.rs +++ b/tokio/tests/unwindsafe.rs @@ -3,6 +3,11 @@ use std::panic::{RefUnwindSafe, UnwindSafe}; +#[test] +fn notify_is_unwind_safe() { + is_unwind_safe::(); +} + #[test] fn join_handle_is_unwind_safe() { is_unwind_safe::>();