forked from Alepha/Alepha
Switch the dead drop to use a circular buffer.
This commit is contained in:
@ -8,6 +8,8 @@ static_assert( __cplusplus > 2020'99 );
|
||||
|
||||
#include <queue>
|
||||
|
||||
#include <boost/circular_buffer.hpp>
|
||||
|
||||
#include <Alepha/Thread.h>
|
||||
|
||||
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();
|
||||
}
|
||||
|
Reference in New Issue
Block a user