sync: make Notify panic safe (#5154)

This commit is contained in:
Yiyu Lin 2022-11-01 21:24:01 +08:00 committed by GitHub
parent b1f40f4356
commit 203a079743
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 0 deletions

View File

@ -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<Waker> {
loop {
match get_state(curr) {

View File

@ -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<()>>();