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: private:
boost::asio::io_service& ioService; boost::asio::io_service& ioService;
protected:
SpinLock shouldContinueLock; SpinLock shouldContinueLock;
bool shouldContinue; bool shouldContinue;
private:
boost::asio::deadline_timer timer; boost::asio::deadline_timer timer;
size_t nDeferrals; size_t nDeferrals;
std::chrono::high_resolution_clock::time_point deferralStartTime; std::chrono::high_resolution_clock::time_point deferralStartTime;
@@ -126,6 +126,13 @@ public:
void produceFrameReq1_doAssemble_posted( void produceFrameReq1_doAssemble_posted(
std::shared_ptr<ProduceFrameReq> context) std::shared_ptr<ProduceFrameReq> context)
{ {
SpinLock::Guard lock(stimBuff.shouldContinueLock);
if (!stimBuff.shouldContinue)
{
callOriginalCallback();
return;
}
stimBuff.ioUringAssemblyEngine.assembleFrameReq( stimBuff.ioUringAssemblyEngine.assembleFrameReq(
{context, std::bind( {context, std::bind(
&ProduceFrameReq::produceFrameReq2_assembleDone, &ProduceFrameReq::produceFrameReq2_assembleDone,
@@ -137,6 +144,13 @@ public:
std::shared_ptr<ProduceFrameReq> context, std::shared_ptr<ProduceFrameReq> context,
bool success, AsynchronousLoop loop) bool success, AsynchronousLoop loop)
{ {
SpinLock::Guard lock(stimBuff.shouldContinueLock);
if (!stimBuff.shouldContinue)
{
callOriginalCallback();
return;
}
if (!success) if (!success)
{ {
std::cerr << __func__ << ": Failed to assemble frame" << std::endl; std::cerr << __func__ << ": Failed to assemble frame" << std::endl;
@@ -158,6 +172,13 @@ public:
[[maybe_unused]] std::shared_ptr<ProduceFrameReq> context, [[maybe_unused]] std::shared_ptr<ProduceFrameReq> context,
bool success, StimulusFrame& /*stimulusFrame*/) bool success, StimulusFrame& /*stimulusFrame*/)
{ {
SpinLock::Guard lock(stimBuff.shouldContinueLock);
if (!stimBuff.shouldContinue)
{
callOriginalCallback();
return;
}
if (!success) { if (!success) {
std::cerr << __func__ << ": Failed to compact and collate frame" << std::endl; std::cerr << __func__ << ": Failed to compact and collate frame" << std::endl;
} else { } else {
@@ -177,6 +198,12 @@ public:
void PcloudStimulusBuffer::produceFrameReq( void PcloudStimulusBuffer::produceFrameReq(
smo::Callback<produceFrameReqCbFn> callback) 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 caller = smoHooksPtr->ComponentThread_getSelf();
auto request = std::make_shared<ProduceFrameReq>( auto request = std::make_shared<ProduceFrameReq>(
*this, caller, std::move(callback)); *this, caller, std::move(callback));