fix(shmem): wake the region ack sender when acks stop

- the ack sender waited up to 500 ms for a full ack batch, also after
  StopAcks(), so each region destruction took at least 500 ms
- wait with a predicate that includes the stop flag
- set the stop flag under the ack mutex, so that the sender cannot miss
  the notification

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Claude
2026-11-02 16:19:51 +00:00
committed by Dennis Klein
parent f92780e9a9
commit 8900606bae

View File

@@ -205,10 +205,9 @@ struct UnmanagedRegion
~UnmanagedRegion()
{
LOG(debug) << "~UnmanagedRegion(): " << fName << " (" << (fControlling ? "controller" : "viewer") << ")";
fStopAcks = true;
SetStopAcks();
if (fAcksSender.joinable()) {
fBlockSendCV.notify_one();
fAcksSender.join();
}
@@ -357,10 +356,8 @@ struct UnmanagedRegion
{
std::unique_lock<std::mutex> lock(fBlockMtx);
// try to get <fAckBunchSize> blocks
if (fBlocksToFree.size() < fAckBunchSize) {
fBlockSendCV.wait_for(lock, std::chrono::milliseconds(500));
}
// try to get <fAckBunchSize> blocks, but do not wait when stopping
fBlockSendCV.wait_for(lock, std::chrono::milliseconds(500), [&] { return fBlocksToFree.size() >= fAckBunchSize || fStopAcks; });
// send whatever blocks we have
blocksToSend = std::min(fBlocksToFree.size(), fAckBunchSize);
@@ -445,12 +442,21 @@ struct UnmanagedRegion
}
}
void SetStopAcks()
{
{
// set under the lock, so that the ack sender cannot miss the notification
std::lock_guard<std::mutex> lock(fBlockMtx);
fStopAcks = true;
}
fBlockSendCV.notify_one();
}
void StopAcks()
{
fStopAcks = true;
SetStopAcks();
if (fAcksSender.joinable()) {
fBlockSendCV.notify_one();
fAcksSender.join();
}