diff --git a/smocore/deviceManager/deviceReattacher.cpp b/smocore/deviceManager/deviceReattacher.cpp index bae5a9f..b8ff1e9 100644 --- a/smocore/deviceManager/deviceReattacher.cpp +++ b/smocore/deviceManager/deviceReattacher.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -35,6 +36,24 @@ void DeviceReattacher::stop() { shouldContinue.store(false); 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()