diff --git a/wpilibc/src/main/native/cpp/Watchdog.cpp b/wpilibc/src/main/native/cpp/Watchdog.cpp index af83617e46..b67f94dfd1 100644 --- a/wpilibc/src/main/native/cpp/Watchdog.cpp +++ b/wpilibc/src/main/native/cpp/Watchdog.cpp @@ -58,10 +58,15 @@ void Watchdog::Thread::Main() { << "s\n"; } } + + // Set expiration flag before calling the callback so any manipulation + // of the flag in the callback (e.g., calling Disable()) isn't + // clobbered. + watchdog->m_isExpired = true; + lock.unlock(); watchdog->m_callback(); lock.lock(); - watchdog->m_isExpired = true; } // Otherwise, a Watchdog removed itself from the queue (it notifies the // scheduler of this) or a spurious wakeup occurred, so just rewait with diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Watchdog.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Watchdog.java index 1a6af68511..7ff8937b6c 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Watchdog.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Watchdog.java @@ -247,10 +247,15 @@ public class Watchdog implements Closeable, Comparable { System.out.format("Watchdog not fed within %.6fs\n", watchdog.m_timeout / 1.0e6); } } + + // Set expiration flag before calling the callback so any + // manipulation of the flag in the callback (e.g., calling + // Disable()) isn't clobbered. + watchdog.m_isExpired = true; + m_queueMutex.unlock(); watchdog.m_callback.run(); m_queueMutex.lock(); - watchdog.m_isExpired = true; } // Otherwise, a Watchdog removed itself from the queue (it notifies // the scheduler of this) or a spurious wakeup occurred, so just