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

@@ -80,6 +80,10 @@ void DriverStation::Run() {
m_packetDataAvailableCond.wait(lock);
}
GetData();
{
std::lock_guard<priority_mutex> lock(m_waitForDataMutex);
m_updatedControlLoopData = true;
}
m_waitForDataCond.notify_all();
if (++period >= 4) {
@@ -554,7 +558,10 @@ uint32_t DriverStation::GetLocation() const {
*/
void DriverStation::WaitForData() {
std::unique_lock<priority_mutex> lock(m_waitForDataMutex);
m_waitForDataCond.wait(lock);
while (!m_updatedControlLoopData) {
m_waitForDataCond.wait(lock);
}
m_updatedControlLoopData = false;
}
/**