Fixed race condition between PIDController enable/disable and PIDWrite() call

To make this work in PIDController.java, the use of synchronized had to be
replaced with ReentrantLock and try-catch blocks. The locking in
PIDController.java was made equivalent to PIDController.cpp and some existing
race conditions in PIDController.java were fixed in the process.

Fixes #30.
This commit is contained in:
Tyler Veness
2017-11-24 00:55:35 -08:00
committed by Peter Johnson
parent a76b1aa800
commit de63e1c8a1
3 changed files with 301 additions and 109 deletions

View File

@@ -172,7 +172,11 @@ class PIDController : public LiveWindowSendable, public PIDInterface {
std::shared_ptr<PIDSource> m_origSource;
LinearDigitalFilter m_filter{nullptr, {}, {}};
mutable wpi::mutex m_mutex;
mutable wpi::mutex m_thisMutex;
// Ensures when Disable() is called, PIDWrite() won't run if Calculate()
// is already running at that time.
mutable wpi::mutex m_pidWriteMutex;
std::unique_ptr<Notifier> m_controlLoop;
Timer m_setpointTimer;