StimBuff: Make produceFrameReq responsive to stop()
This commit is contained in:
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user