Places while loop around DS wait condition. (#83)

In case of Spontaneous wake ups, we should be checking a condition
variable as well.

Note that we can not use the existing m_newControlData, as that has a
possible race condition with existing user code that it does not look
like we could work around.
This commit is contained in:
Thad House
2016-05-26 23:05:08 -07:00
committed by Peter Johnson
parent ed7d2d6aa6
commit c622c03eff
3 changed files with 15 additions and 2 deletions

View File

@@ -99,6 +99,7 @@ public class DriverStation implements RobotState.Interface {
private boolean m_userInAutonomous = false;
private boolean m_userInTeleop = false;
private boolean m_userInTest = false;
private boolean m_updatedControlLoopData;
private boolean m_newControlData;
private final long m_packetDataAvailableMutex;
private final long m_packetDataAvailableSem;
@@ -160,6 +161,7 @@ public class DriverStation implements RobotState.Interface {
HALUtil.takeMultiWait(m_packetDataAvailableSem, m_packetDataAvailableMutex);
getData();
synchronized (m_dataSem) {
m_updatedControlLoopData = true;
m_dataSem.notifyAll();
}
if (++safetyCounter >= 4) {
@@ -197,7 +199,10 @@ public class DriverStation implements RobotState.Interface {
public void waitForData(long timeout) {
synchronized (m_dataSem) {
try {
m_dataSem.wait(timeout);
while (!m_updatedControlLoopData) {
m_dataSem.wait(timeout);
}
m_updatedControlLoopData = false;
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}