LivoxGen1: Use syncCancelerForAsyncWork in producer pipeline

This commit is contained in:
2026-05-29 14:10:45 -04:00
parent 5a9fe12057
commit d788810a05
7 changed files with 507 additions and 442 deletions
@@ -8,7 +8,6 @@
#include <boost/system/error_code.hpp>
#include <opts.h>
#include <componentThread.h>
#include <spinscale/spinLock.h>
#include <user/stimulusProducer.h>
#include <user/stimulusBuffer.h>
@@ -91,10 +90,7 @@ void StimulusProducer::destroyAttachedStimulusBuffer(
void StimulusProducer::stop()
{
{
sscl::SpinLock::Guard lock(shouldContinueLock);
shouldContinue = false;
}
(void)stimulusProducerCanceler.requestStop();
// Cancel timer immediately
timer.cancel();
@@ -105,7 +101,7 @@ void StimulusProducer::stop()
void StimulusProducer::scheduleNextTimeout(int delayMs)
{
if (!shouldContinue)
if (stimulusProducerCanceler.isCancellationRequestedUnlocked())
{ return; }
// Schedule the next timeout using the provided delay
@@ -131,10 +127,6 @@ void StimulusProducer::onTimeout(const boost::system::error_code& error)
return;
}
sscl::SpinLock::Guard lock(shouldContinueLock);
if (!shouldContinue)
{ return; }
/** EXPLANATION:
* We need to ensure that there's only ever one stimframe being produced
* during any CONFIG_STIMBUFF_FRAME_PERIOD_MS period. To guarantee this, we
@@ -148,35 +140,39 @@ void StimulusProducer::onTimeout(const boost::system::error_code& error)
*/
int nextWakeupDelayMs;
bool deferred = false;
if (frameAssemblyRateLimiter.tryAcquire())
bool shouldContinue;
shouldContinue = stimulusProducerCanceler.execUncancelableSegmentOrAbort(
[&]()
{
nextWakeupDelayMs = CONFIG_STIMBUFF_FRAME_PERIOD_MS;
// Check if we're ending a deferral period
if (nDeferrals > 0)
if (frameAssemblyRateLimiter.tryAcquire())
{
auto deferralEndTime = std::chrono::high_resolution_clock::now();
auto duration = deferralEndTime - deferralStartTime;
auto durationMs = std::chrono::duration_cast<
std::chrono::milliseconds>(duration);
nextWakeupDelayMs = CONFIG_STIMBUFF_FRAME_PERIOD_MS;
std::cout << __func__ << ": Deferral period ended. "
<< "Total deferrals: " << nDeferrals
<< ", Duration: " << durationMs.count() << "ms" << std::endl;
// Check if we're ending a deferral period
if (nDeferrals > 0)
{
auto deferralEndTime = std::chrono::high_resolution_clock::now();
auto duration = deferralEndTime - deferralStartTime;
auto durationMs = std::chrono::duration_cast<
std::chrono::milliseconds>(duration);
nDeferrals = 0;
std::cout << __func__ << ": Deferral period ended. "
<< "Total deferrals: " << nDeferrals
<< ", Duration: " << durationMs.count() << "ms" << std::endl;
nDeferrals = 0;
}
/** EXPLANATION:
* Call the derived class's frame production handler
* Note: The derived class's frame production handler (aka
* its implementation of stimFrameProductionTimesliceInd()) must
* release the lock when frame production completes
*/
stimFrameProductionTimesliceInd();
return;
}
/** EXPLANATION:
* Call the derived class's frame production handler
* Note: The derived class's frame production handler (aka
* its implementation of stimFrameProductionTimesliceInd()) must
* release the lock when frame production completes
*/
stimFrameProductionTimesliceInd();
}
else
{
nextWakeupDelayMs = CONFIG_STIMBUFF_FRAME_RETRY_DELAY_MS;
deferred = true;
@@ -189,7 +185,9 @@ void StimulusProducer::onTimeout(const boost::system::error_code& error)
"Configured deferral period: " << nextWakeupDelayMs << "ms"
<< std::endl;
}
}
});
if (!shouldContinue) { return; }
scheduleNextTimeout(nextWakeupDelayMs);