From 3728bc3b5c712280685f9948ec46aa8392905633 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Fri, 10 Apr 2026 12:28:54 -0700 Subject: [PATCH] [wpilibc] Notifier: Use atomic exchange in move constructor/assignment (#8740) --- wpilibc/src/main/native/cpp/system/Notifier.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/wpilibc/src/main/native/cpp/system/Notifier.cpp b/wpilibc/src/main/native/cpp/system/Notifier.cpp index 03bca34dc6..5a7fa4f01c 100644 --- a/wpilibc/src/main/native/cpp/system/Notifier.cpp +++ b/wpilibc/src/main/native/cpp/system/Notifier.cpp @@ -72,7 +72,7 @@ Notifier::Notifier(int priority, std::function callback) { Notifier::~Notifier() { // atomically set handle to 0, then clean - HAL_NotifierHandle handle = m_notifier.exchange(0); + HAL_NotifierHandle handle = m_notifier.exchange(HAL_INVALID_HANDLE); HAL_DestroyNotifier(handle); // Join the thread to ensure the callback has exited. @@ -83,15 +83,12 @@ Notifier::~Notifier() { Notifier::Notifier(Notifier&& rhs) : m_thread(std::move(rhs.m_thread)), - m_notifier(rhs.m_notifier.load()), - m_callback(std::move(rhs.m_callback)) { - rhs.m_notifier = HAL_INVALID_HANDLE; -} + m_notifier(rhs.m_notifier.exchange(HAL_INVALID_HANDLE)), + m_callback(std::move(rhs.m_callback)) {} Notifier& Notifier::operator=(Notifier&& rhs) { m_thread = std::move(rhs.m_thread); - m_notifier = rhs.m_notifier.load(); - rhs.m_notifier = HAL_INVALID_HANDLE; + m_notifier = rhs.m_notifier.exchange(HAL_INVALID_HANDLE); m_callback = std::move(rhs.m_callback); return *this; }