From da34142bf1719cbd18107229352c330ff7a64ff3 Mon Sep 17 00:00:00 2001 From: ADAM David Alan Martin Date: Fri, 5 Jan 2024 23:57:47 -0500 Subject: [PATCH] Fix stalls due to lacking custom terminal notifications. `Dropbox` and `Mailbox` should be roughly the same interface, but with different stall semantics. However, terminal operations don't wait. `finish( custom )` should be a handoff without wait. `Dropbox`'s primary thread-coordination works in terms of an acquire/release semantic whereby `release` doesn't block, so this naturally works. However, `Mailbox` works in terms of the `Interlock` primitive which allows for a terminal-case `checkpoint`. Therefore `finish( custom )` has to call the `checkpoint` api in `Mailbox` --- Atomic/Dropbox.h | 10 +++++++++- Atomic/Mailbox.h | 15 ++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/Atomic/Dropbox.h b/Atomic/Dropbox.h index 5967c24..312fddb 100644 --- a/Atomic/Dropbox.h +++ b/Atomic/Dropbox.h @@ -153,10 +153,18 @@ namespace Alepha::Hydrogen::Atomic ::detail:: Dropbox_m sendoff(); } + void + finish( auto newNotification ) + { + auto &preparing= drops.producer.acquireBox(); + preparing.notification= std::make_exception_ptr( std::move( newNotification ) ); + sendoff(); + } + void finish() { - notify( build_exception< FinishedCondition >( "" ) ); + finish( build_exception< FinishedCondition >( "" ) ); } }; } diff --git a/Atomic/Mailbox.h b/Atomic/Mailbox.h index 12ac6ba..d420327 100644 --- a/Atomic/Mailbox.h +++ b/Atomic/Mailbox.h @@ -241,6 +241,19 @@ namespace Alepha::Hydrogen::Atomic ::detail:: Mailbox_m checkpoint( lock ); } + /*! + * @brief This function will pump the mailbox, and deliver a custom notification + * event to the other side, without waiting (last step). + */ + void + finish( auto newNotification ) + { + auto notification_ptr= std::make_exception_ptr( std::move( newNotification ) ); + Alepha::unique_lock lock( access ); + notification= std::move( notification_ptr ); + checkpoint( lock ); + } + /*! * @brief This function will pump the mailbox, and deliver a custom notification @@ -249,7 +262,7 @@ namespace Alepha::Hydrogen::Atomic ::detail:: Mailbox_m void notify( auto newNotification ) { - auto notification_ptr= std::make_exception_ptr( std::move( notification ) ); + auto notification_ptr= std::make_exception_ptr( std::move( newNotification ) ); Alepha::unique_lock lock( access ); assertion( not finished ); notification= std::move( notification_ptr );