mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-28 02:11:43 +00:00
Merge "[artf3749] Repaired undefined behavior in takeMultiWait."
This commit is contained in:
@@ -46,7 +46,7 @@ extern "C"
|
||||
|
||||
MULTIWAIT_ID initializeMultiWait();
|
||||
void deleteMultiWait(MULTIWAIT_ID sem);
|
||||
int8_t takeMultiWait(MULTIWAIT_ID sem, int32_t timeout);
|
||||
int8_t takeMultiWait(MULTIWAIT_ID sem, MUTEX_ID m, int32_t timeout);
|
||||
int8_t giveMultiWait(MULTIWAIT_ID sem);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
#include "HAL/Semaphore.hpp"
|
||||
|
||||
#include "Log.hpp"
|
||||
@@ -122,11 +121,10 @@ void deleteMultiWait(MULTIWAIT_ID sem) {
|
||||
delete sem;
|
||||
}
|
||||
|
||||
int8_t takeMultiWait(MULTIWAIT_ID sem, int32_t timeout) {
|
||||
MUTEX_ID m = initializeMutexNormal();
|
||||
int8_t takeMultiWait(MULTIWAIT_ID sem, MUTEX_ID m, int32_t timeout) {
|
||||
takeMutex(m);
|
||||
int8_t val = pthread_cond_wait(sem, m);
|
||||
deleteMutex(m);
|
||||
giveMutex(m);
|
||||
return val;
|
||||
}
|
||||
|
||||
|
||||
@@ -107,6 +107,7 @@ private:
|
||||
SEMAPHORE_ID m_newControlData;
|
||||
MUTEX_ID m_packetDataAvailableSem;
|
||||
MULTIWAIT_ID m_waitForDataSem;
|
||||
MUTEX_ID m_waitForDataMutex;
|
||||
double m_approxMatchTimeOffset;
|
||||
bool m_userInDisabled;
|
||||
bool m_userInAutonomous;
|
||||
|
||||
@@ -61,6 +61,7 @@ DriverStation::DriverStation()
|
||||
HALSetNewDataSem(m_packetDataAvailableSem);
|
||||
|
||||
m_waitForDataSem = initializeMultiWait();
|
||||
m_waitForDataMutex = initializeMutexNormal();
|
||||
|
||||
AddToSingletonList();
|
||||
|
||||
@@ -79,6 +80,7 @@ DriverStation::~DriverStation()
|
||||
// Unregister our semaphore.
|
||||
HALSetNewDataSem(0);
|
||||
deleteMutex(m_packetDataAvailableSem);
|
||||
deleteMutex(m_waitForDataMutex);
|
||||
}
|
||||
|
||||
void DriverStation::InitTask(DriverStation *ds)
|
||||
@@ -353,7 +355,7 @@ uint32_t DriverStation::GetLocation()
|
||||
*/
|
||||
void DriverStation::WaitForData()
|
||||
{
|
||||
takeMultiWait(m_waitForDataSem, SEMAPHORE_WAIT_FOREVER);
|
||||
takeMultiWait(m_waitForDataSem, m_waitForDataMutex, SEMAPHORE_WAIT_FOREVER);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -118,8 +118,9 @@ private:
|
||||
|
||||
uint8_t m_digitalOut;
|
||||
MULTIWAIT_ID m_waitForDataSem;
|
||||
MUTEX_ID m_stateSemaphore;
|
||||
MUTEX_ID m_joystickSemaphore;
|
||||
MUTEX_ID m_waitForDataMutex;
|
||||
MUTEX_ID m_stateSemaphore;
|
||||
MUTEX_ID m_joystickSemaphore;
|
||||
double m_approxMatchTimeOffset;
|
||||
bool m_userInDisabled;
|
||||
bool m_userInAutonomous;
|
||||
|
||||
@@ -3,5 +3,6 @@
|
||||
namespace wpilib { namespace internal {
|
||||
extern double simTime;
|
||||
extern MULTIWAIT_ID time_wait;
|
||||
extern MUTEX_ID time_wait_mutex;
|
||||
// transport::SubscriberPtr time_sub;
|
||||
}}
|
||||
|
||||
@@ -45,6 +45,7 @@ DriverStation::DriverStation()
|
||||
{
|
||||
// Create a new semaphore
|
||||
m_waitForDataSem = initializeMultiWait();
|
||||
m_waitForDataMutex = initializeMutexNormal();
|
||||
m_stateSemaphore = initializeMutexRecursive();
|
||||
m_joystickSemaphore = initializeMutexRecursive();
|
||||
|
||||
@@ -78,6 +79,7 @@ DriverStation::~DriverStation()
|
||||
{
|
||||
m_instance = NULL;
|
||||
deleteMultiWait(m_waitForDataSem);
|
||||
deleteMutex(m_waitForDataMutex);
|
||||
// TODO: Release m_stateSemaphore and m_joystickSemaphore?
|
||||
}
|
||||
|
||||
@@ -311,7 +313,7 @@ uint32_t DriverStation::GetLocation()
|
||||
*/
|
||||
void DriverStation::WaitForData()
|
||||
{
|
||||
takeMultiWait(m_waitForDataSem, SEMAPHORE_WAIT_FOREVER);
|
||||
takeMultiWait(m_waitForDataSem, m_waitForDataMutex, SEMAPHORE_WAIT_FOREVER);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -28,7 +28,8 @@ void Wait(double seconds)
|
||||
double start = wpilib::internal::simTime;
|
||||
|
||||
while ((wpilib::internal::simTime - start) < seconds) {
|
||||
takeMultiWait(wpilib::internal::time_wait, 0);
|
||||
takeMultiWait(wpilib::internal::time_wait,
|
||||
wpilib::internal::time_wait_mutex, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,6 +204,7 @@ extern "C"
|
||||
namespace wpilib { namespace internal {
|
||||
double simTime = 0;
|
||||
MULTIWAIT_ID time_wait = initializeMultiWait();
|
||||
MUTEX_ID time_wait_mutex = initializeMutexNormal();
|
||||
|
||||
void time_callback(const msgs::ConstFloat64Ptr &msg) {
|
||||
simTime = msg->data();
|
||||
|
||||
Reference in New Issue
Block a user