Files
salmanoff/smocore/include/deviceManager/deviceReattacher.h
T
hayodea 2a8d320f7a DevReattacher: Spinlock-protect stop() call
Replace the current delay timeout mechanism with a spinlock.
Both mechanisms try to eliminate the possibility of an in-flight
async op accessing state that has been destroyed by stop().

But the spinlock is less arbitrary.
2025-11-27 22:52:09 -04:00

48 lines
982 B
C++

#ifndef DEVICEREATTACHER_H
#define DEVICEREATTACHER_H
#include <boostAsioLinkageFix.h>
#include <atomic>
#include <memory>
#include <boost/asio/deadline_timer.hpp>
#include <spinLock.h>
namespace smo {
class ComponentThread;
namespace device {
class DeviceManager;
class DeviceReattacher
{
public:
DeviceReattacher(
DeviceManager& parent, std::shared_ptr<ComponentThread> ioThread);
~DeviceReattacher() = default;
// Non-copyable
DeviceReattacher(const DeviceReattacher&) = delete;
DeviceReattacher& operator=(const DeviceReattacher&) = delete;
// Control methods
void start();
void stop();
private:
void scheduleNextTimeout();
void onTimeout(const boost::system::error_code& error);
DeviceManager &parent;
std::shared_ptr<ComponentThread> ioThread;
SpinLock shouldContinueLock;
bool shouldContinue;
boost::asio::deadline_timer timer;
};
} // namespace device
} // namespace smo
#endif // DEVICEREATTACHER_H