DevReattacher: Add 20ms sync delay during stop()
This fixes the bug where in-flight async ops that were triggered by DevReattacher (such as livoxGen1_attachDeviceReq) that have unconditional delays in them would fire late, after the state var they rely upon had already been de-initialized. We use an async bridge to ensure that those ops get executed in the background and then resume execution after the delay.
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
#include <functional>
|
#include <functional>
|
||||||
#include <componentThread.h>
|
#include <componentThread.h>
|
||||||
#include <callback.h>
|
#include <callback.h>
|
||||||
|
#include <asynchronousBridge.h>
|
||||||
#include <deviceManager/deviceReattacher.h>
|
#include <deviceManager/deviceReattacher.h>
|
||||||
#include <deviceManager/deviceManager.h>
|
#include <deviceManager/deviceManager.h>
|
||||||
|
|
||||||
@@ -35,6 +36,24 @@ void DeviceReattacher::stop()
|
|||||||
{
|
{
|
||||||
shouldContinue.store(false);
|
shouldContinue.store(false);
|
||||||
timer.cancel();
|
timer.cancel();
|
||||||
|
|
||||||
|
// Set up a timeout bridge using Marionette thread's io_service
|
||||||
|
auto& mrnttIoService = ComponentThread::getMrntt()->getIoService();
|
||||||
|
boost::asio::deadline_timer timeoutTimer(mrnttIoService);
|
||||||
|
AsynchronousBridge bridge(mrnttIoService);
|
||||||
|
|
||||||
|
// Set up the timeout for ~10ms
|
||||||
|
timeoutTimer.expires_from_now(boost::posix_time::milliseconds(20));
|
||||||
|
timeoutTimer.async_wait(
|
||||||
|
[&bridge](const boost::system::error_code& error)
|
||||||
|
{
|
||||||
|
(void)error;
|
||||||
|
|
||||||
|
// Always signal complete, whether timeout expired or was cancelled
|
||||||
|
bridge.setAsyncOperationComplete();
|
||||||
|
});
|
||||||
|
|
||||||
|
bridge.waitForAsyncOperationCompleteOrIoServiceStopped();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceReattacher::scheduleNextTimeout()
|
void DeviceReattacher::scheduleNextTimeout()
|
||||||
|
|||||||
Reference in New Issue
Block a user