From 4dbb27fd1fd9dc492f556e7ce221283ca2c15d2a Mon Sep 17 00:00:00 2001 From: Hayodea Hekol Date: Wed, 12 Nov 2025 12:31:37 -0400 Subject: [PATCH] StimulusBuffer: properly serialize timeslices We previously unintentionally allowed multiple production operations to occur in the same timeslice because we were calling for production even when deferring timeslices. --- .../attachmentSupport/stimulusBuffer.cpp | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/commonLibs/attachmentSupport/stimulusBuffer.cpp b/commonLibs/attachmentSupport/stimulusBuffer.cpp index 2ebdfba..7388cd3 100644 --- a/commonLibs/attachmentSupport/stimulusBuffer.cpp +++ b/commonLibs/attachmentSupport/stimulusBuffer.cpp @@ -86,16 +86,21 @@ void StimulusBuffer::onTimeout(const boost::system::error_code& error) */ int nextWakeupDelayMs; if (frameAssemblyRateLimiter.tryAcquire()) - { nextWakeupDelayMs = CONFIG_STIMBUFF_FRAME_PERIOD_MS; } - else - { + { + nextWakeupDelayMs = CONFIG_STIMBUFF_FRAME_PERIOD_MS; + + /** 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 { std::cout << __func__ << ": Deferring frame production due to rate limit." << std::endl; nextWakeupDelayMs = CONFIG_STIMBUFF_FRAME_RETRY_DELAY_MS; - } - - // Call the derived class's frame production handler - stimFrameProductionTimesliceInd(); - // Note: The lock should be released when frame production completes + } // Schedule next timeout with the pre-determined duration scheduleNextTimeout(nextWakeupDelayMs);