From 4045c30021130aa121b5f599b49746ac2e1ecce8 Mon Sep 17 00:00:00 2001 From: ADAM David Alan Martin Date: Fri, 24 May 2024 13:28:16 -0400 Subject: [PATCH] Switch the dead drop to use a circular buffer. --- Atomic/DeadDrop.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Atomic/DeadDrop.h b/Atomic/DeadDrop.h index da06d6c..679a9f9 100644 --- a/Atomic/DeadDrop.h +++ b/Atomic/DeadDrop.h @@ -8,6 +8,8 @@ static_assert( __cplusplus > 2020'99 ); #include +#include + #include namespace Alepha::Hydrogen::Atomic ::detail:: DeadDrop_m @@ -33,7 +35,7 @@ namespace Alepha::Hydrogen::Atomic ::detail:: DeadDrop_m Item original; Item *active= &original; - std::queue< Item * > next; + boost::circular_buffer< Item * > next{ 2 }; Box *companion= nullptr; @@ -56,7 +58,7 @@ namespace Alepha::Hydrogen::Atomic ::detail:: DeadDrop_m std::unique_lock lock{ *access }; ready.wait( lock, [&]{ return not next.empty(); } ); active= next.front(); - next.pop(); + next.pop_front(); } assert( active ); return *active; @@ -66,7 +68,7 @@ namespace Alepha::Hydrogen::Atomic ::detail:: DeadDrop_m releaseBox() { std::unique_lock lock{ *access }; - companion->next.push( active ); + companion->next.push_back( active ); active= nullptr; companion->ready.notify_one(); }