StimBuff: Make produceFrameReq responsive to stop()

This commit is contained in:
2025-11-14 02:23:04 -04:00
parent c268414b0d
commit 0720ed9c76
2 changed files with 29 additions and 0 deletions
+2
View File
@@ -107,8 +107,10 @@ protected:
private:
boost::asio::io_service& ioService;
protected:
SpinLock shouldContinueLock;
bool shouldContinue;
private:
boost::asio::deadline_timer timer;
size_t nDeferrals;
std::chrono::high_resolution_clock::time_point deferralStartTime;
@@ -126,6 +126,13 @@ public:
void produceFrameReq1_doAssemble_posted(
std::shared_ptr<ProduceFrameReq> context)
{
SpinLock::Guard lock(stimBuff.shouldContinueLock);
if (!stimBuff.shouldContinue)
{
callOriginalCallback();
return;
}
stimBuff.ioUringAssemblyEngine.assembleFrameReq(
{context, std::bind(
&ProduceFrameReq::produceFrameReq2_assembleDone,
@@ -137,6 +144,13 @@ public:
std::shared_ptr<ProduceFrameReq> context,
bool success, AsynchronousLoop loop)
{
SpinLock::Guard lock(stimBuff.shouldContinueLock);
if (!stimBuff.shouldContinue)
{
callOriginalCallback();
return;
}
if (!success)
{
std::cerr << __func__ << ": Failed to assemble frame" << std::endl;
@@ -158,6 +172,13 @@ public:
[[maybe_unused]] std::shared_ptr<ProduceFrameReq> context,
bool success, StimulusFrame& /*stimulusFrame*/)
{
SpinLock::Guard lock(stimBuff.shouldContinueLock);
if (!stimBuff.shouldContinue)
{
callOriginalCallback();
return;
}
if (!success) {
std::cerr << __func__ << ": Failed to compact and collate frame" << std::endl;
} else {
@@ -177,6 +198,12 @@ public:
void PcloudStimulusBuffer::produceFrameReq(
smo::Callback<produceFrameReqCbFn> callback)
{
/** EXPLANATION:
* We shouldn't acquire the StimulusBuffer::shouldContinueLock here because
* this function is called from
* StimulusBuffer::stimFrameProductionTimesliceInd(), which is already
* holding the lock.
*/
auto caller = smoHooksPtr->ComponentThread_getSelf();
auto request = std::make_shared<ProduceFrameReq>(
*this, caller, std::move(callback));