From 892743ac29127ba12869823d174da52afdc0bb54 Mon Sep 17 00:00:00 2001 From: orignal Date: Sat, 7 Mar 2026 15:18:11 -0500 Subject: [PATCH] replace std:atomic by std::atomic_flag for m_Dead --- libi2pd_client/I2PService.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/libi2pd_client/I2PService.h b/libi2pd_client/I2PService.h index 328ae29b..80d0ba8c 100644 --- a/libi2pd_client/I2PService.h +++ b/libi2pd_client/I2PService.h @@ -97,7 +97,11 @@ namespace client { public: - I2PServiceHandler(I2PService * parent) : m_Service(parent), m_Dead(false) { } + I2PServiceHandler(I2PService * parent) : m_Service(parent) +#if __cplusplus < 202002L // C++20 + , m_Dead (ATOMIC_FLAG_INIT) +#endif + { } virtual ~I2PServiceHandler() { } //If you override this make sure you call it from the children virtual void Handle() {}; //Start handling the socket @@ -108,9 +112,7 @@ namespace client protected: // Call when terminating or handing over to avoid race conditions - inline bool Kill () { return m_Dead.exchange(true); } - // Call to know if the handler is dead - inline bool Dead () { return m_Dead; } + inline bool Kill () { return m_Dead.test_and_set (); } // Call when done to clean up (make sure Kill is called first) inline void Done (std::shared_ptr me) { if(m_Service) m_Service->RemoveHandler(me); } // Call to talk with the owner @@ -119,7 +121,7 @@ namespace client private: I2PService *m_Service; - std::atomic m_Dead; //To avoid cleaning up multiple times + std::atomic_flag m_Dead; //To avoid cleaning up multiple times }; const size_t SOCKETS_PIPE_BUFFER_SIZE = 8192 * 8;