Nursery: Initial integration
StimulusProducer: syncAwaitAllSettlements should pump caller io_context
This commit is contained in:
@@ -355,8 +355,11 @@ attachByCreatingProducer(
|
||||
* may not yet be ready for another command.
|
||||
*/
|
||||
// Initialize timer with LivoxGen1 metadata io_context
|
||||
boost::asio::deadline_timer commandDelayTimer(
|
||||
componentThread->getIoContext());
|
||||
const bool delayOk = co_await adapters::boostAsio::getDeadlineTimerAReqAwaiter(
|
||||
componentThread->getIoContext(),
|
||||
commandDelayTimer,
|
||||
boost::posix_time::milliseconds(LIVOX_GEN1_DEVICE_COMMAND_DELAY_MS));
|
||||
|
||||
if (!delayOk)
|
||||
@@ -540,10 +543,13 @@ livoxGen1_detachDeviceCReq(
|
||||
|
||||
// Add 5ms delay before destroying device
|
||||
|
||||
// Helper method to delay and then call destroyDeviceReq
|
||||
// Initialize timer with LivoxGen1 metadata io_context
|
||||
// Helper method to delay and then call destroyDeviceReq
|
||||
// Initialize timer with LivoxGen1 metadata io_context
|
||||
boost::asio::deadline_timer commandDelayTimer(
|
||||
requestComponentThread->getIoContext());
|
||||
co_await adapters::boostAsio::getDeadlineTimerAReqAwaiter(
|
||||
requestComponentThread->getIoContext(),
|
||||
commandDelayTimer,
|
||||
boost::posix_time::milliseconds(LIVOX_GEN1_DEVICE_COMMAND_DELAY_MS));
|
||||
|
||||
// No other buffers - stop and remove StimProducer
|
||||
|
||||
@@ -428,11 +428,6 @@ PcloudStimulusProducer::getOrCreateAttachedStimulusBuffer(
|
||||
}
|
||||
}
|
||||
|
||||
void PcloudStimulusProducer::stimFrameProductionTimesliceInd()
|
||||
{
|
||||
holdProduceFrameCReq();
|
||||
}
|
||||
|
||||
struct AllowNextStimulusFrameGuard
|
||||
{
|
||||
PcloudStimulusProducer& producer;
|
||||
@@ -445,22 +440,14 @@ struct AllowNextStimulusFrameGuard
|
||||
{ producer.allowNextStimulusFrame(); }
|
||||
};
|
||||
|
||||
void PcloudStimulusProducer::holdProduceFrameCReq()
|
||||
{
|
||||
/** EXPLANATION:
|
||||
* We shouldn't acquire stimulusProducerCanceler.s.lock here because
|
||||
* this function is called from
|
||||
* StimulusProducer::stimFrameProductionTimesliceInd(), which is already
|
||||
* holding the lock.
|
||||
*/
|
||||
activeProduceFrameInvoker.emplace(produceFrameCReq(
|
||||
produceFrameExceptionPtr,
|
||||
[this]() { activeProduceFrameInvoker.reset(); }));
|
||||
}
|
||||
|
||||
sscl::co::NonViralNonPostingInvoker PcloudStimulusProducer::produceFrameCReq(
|
||||
[[maybe_unused]] std::exception_ptr& exceptionPtr,
|
||||
[[maybe_unused]] std::function<void()> completion)
|
||||
/** EXPLANATION:
|
||||
* productionCDaemon co_awaits this viral timeslice and passes its
|
||||
* nursery-slot canceler. Cooperative shutdown uses that canceler between
|
||||
* co_await steps; do not use execUncancelableSegmentOrAbort here.
|
||||
*/
|
||||
sscl::co::ViralNonPostingInvoker<void>
|
||||
PcloudStimulusProducer::stimFrameProductionTimesliceCInd(
|
||||
sscl::SyncCancelerForAsyncWork &canceler)
|
||||
{
|
||||
AllowNextStimulusFrameGuard allowNextGuard(*this);
|
||||
StimulusFrame& stimulusFrame = tempStimulusFrame;
|
||||
@@ -473,14 +460,11 @@ sscl::co::NonViralNonPostingInvoker PcloudStimulusProducer::produceFrameCReq(
|
||||
|
||||
// produceFrameReq1_doAssemble_posted
|
||||
/** EXPLANATION:
|
||||
* stimFrameProductionTimesliceInd() is entered with
|
||||
* stimulusProducerCanceler.s.lock held; do not re-acquire here.
|
||||
*
|
||||
* This function is called from
|
||||
* StimulusProducer::stimFrameProductionTimesliceInd(), whose caller is
|
||||
* already holding the lock.
|
||||
* productionCDaemon co_awaits this timeslice outside its uncancelable
|
||||
* rate-limiter segment; use isCancellationRequested() here, not
|
||||
* execUncancelableSegmentOrAbort.
|
||||
*/
|
||||
if (stimulusProducerCanceler.isCancellationRequestedUnlocked())
|
||||
if (canceler.isCancellationRequested())
|
||||
{ co_return; }
|
||||
|
||||
cpsBoundary::AssembleFrameResult assembleResult = co_await
|
||||
@@ -491,8 +475,8 @@ sscl::co::NonViralNonPostingInvoker PcloudStimulusProducer::produceFrameCReq(
|
||||
std::optional<AmbienceProductionDesc> lightAmbienceProductionDescDesc;
|
||||
std::optional<AmbienceProductionDesc> darkAmbienceProductionDescDesc;
|
||||
{
|
||||
sscl::SpinLock::Guard guard(stimulusProducerCanceler.s.lock);
|
||||
if (stimulusProducerCanceler.isCancellationRequestedUnlocked())
|
||||
sscl::SpinLock::Guard guard(canceler.s.lock);
|
||||
if (canceler.isCancellationRequestedUnlocked())
|
||||
{ co_return; }
|
||||
|
||||
if (!assembleResult.success)
|
||||
@@ -612,8 +596,8 @@ sscl::co::NonViralNonPostingInvoker PcloudStimulusProducer::produceFrameCReq(
|
||||
}
|
||||
|
||||
{
|
||||
sscl::SpinLock::Guard guard(stimulusProducerCanceler.s.lock);
|
||||
if (stimulusProducerCanceler.isCancellationRequestedUnlocked())
|
||||
sscl::SpinLock::Guard guard(canceler.s.lock);
|
||||
if (canceler.isCancellationRequestedUnlocked())
|
||||
{ co_return; }
|
||||
|
||||
if (!compactCollateSuccess) {
|
||||
|
||||
@@ -82,13 +82,9 @@ public:
|
||||
const std::shared_ptr<StimulusBuffer>& buffer) override;
|
||||
|
||||
protected:
|
||||
void stimFrameProductionTimesliceInd() override;
|
||||
|
||||
void holdProduceFrameCReq();
|
||||
|
||||
sscl::co::NonViralNonPostingInvoker produceFrameCReq(
|
||||
std::exception_ptr& exceptionPtr,
|
||||
std::function<void()> completion);
|
||||
sscl::co::ViralNonPostingInvoker<void>
|
||||
stimFrameProductionTimesliceCInd(
|
||||
sscl::SyncCancelerForAsyncWork &canceler) override;
|
||||
|
||||
public:
|
||||
size_t nDgramsPerStagingBufferFrame;
|
||||
@@ -112,9 +108,6 @@ public:
|
||||
lightAmbienceStimulusBuffer;
|
||||
std::atomic<std::shared_ptr<PcloudDarkAmbienceStimulusBuffer>>
|
||||
darkAmbienceStimulusBuffer;
|
||||
|
||||
std::optional<sscl::co::NonViralNonPostingInvoker> activeProduceFrameInvoker;
|
||||
std::exception_ptr produceFrameExceptionPtr;
|
||||
};
|
||||
|
||||
} // namespace stim_buff
|
||||
|
||||
Reference in New Issue
Block a user