mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
Use wpi::mutex instead of std::mutex. (#730)
This uses a priority-aware mutex on Linux platforms. Fixes #729.
This commit is contained in:
@@ -7,9 +7,8 @@
|
||||
|
||||
#include "HAL/AnalogInput.h"
|
||||
|
||||
#include <mutex>
|
||||
|
||||
#include <FRC_NetworkCommunication/AICalibration.h>
|
||||
#include <support/mutex.h>
|
||||
|
||||
#include "AnalogInternal.h"
|
||||
#include "HAL/AnalogAccumulator.h"
|
||||
@@ -230,7 +229,7 @@ int32_t HAL_GetAnalogValue(HAL_AnalogInputHandle analogPortHandle,
|
||||
readSelect.Channel = port->channel;
|
||||
readSelect.Averaged = false;
|
||||
|
||||
std::lock_guard<std::mutex> sync(analogRegisterWindowMutex);
|
||||
std::lock_guard<wpi::mutex> sync(analogRegisterWindowMutex);
|
||||
analogInputSystem->writeReadSelect(readSelect, status);
|
||||
analogInputSystem->strobeLatchOutput(status);
|
||||
return static_cast<int16_t>(analogInputSystem->readOutput(status));
|
||||
@@ -261,7 +260,7 @@ int32_t HAL_GetAnalogAverageValue(HAL_AnalogInputHandle analogPortHandle,
|
||||
readSelect.Channel = port->channel;
|
||||
readSelect.Averaged = true;
|
||||
|
||||
std::lock_guard<std::mutex> sync(analogRegisterWindowMutex);
|
||||
std::lock_guard<wpi::mutex> sync(analogRegisterWindowMutex);
|
||||
analogInputSystem->writeReadSelect(readSelect, status);
|
||||
analogInputSystem->strobeLatchOutput(status);
|
||||
return static_cast<int32_t>(analogInputSystem->readOutput(status));
|
||||
|
||||
@@ -8,7 +8,8 @@
|
||||
#include "AnalogInternal.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <mutex>
|
||||
|
||||
#include <support/mutex.h>
|
||||
|
||||
#include "HAL/AnalogInput.h"
|
||||
#include "HAL/ChipObject.h"
|
||||
@@ -16,7 +17,7 @@
|
||||
|
||||
namespace hal {
|
||||
|
||||
std::mutex analogRegisterWindowMutex;
|
||||
wpi::mutex analogRegisterWindowMutex;
|
||||
std::unique_ptr<tAI> analogInputSystem;
|
||||
std::unique_ptr<tAO> analogOutputSystem;
|
||||
|
||||
@@ -35,7 +36,7 @@ bool analogSampleRateSet = false;
|
||||
*/
|
||||
void initializeAnalog(int32_t* status) {
|
||||
if (analogSystemInitialized) return;
|
||||
std::lock_guard<std::mutex> sync(analogRegisterWindowMutex);
|
||||
std::lock_guard<wpi::mutex> sync(analogRegisterWindowMutex);
|
||||
if (analogSystemInitialized) return;
|
||||
analogInputSystem.reset(tAI::create(status));
|
||||
analogOutputSystem.reset(tAO::create(status));
|
||||
|
||||
@@ -10,7 +10,8 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
#include <support/mutex.h>
|
||||
|
||||
#include "HAL/ChipObject.h"
|
||||
#include "HAL/Ports.h"
|
||||
@@ -27,7 +28,7 @@ static const uint32_t kAccumulatorChannels[] = {0, 1};
|
||||
|
||||
extern std::unique_ptr<tAI> analogInputSystem;
|
||||
extern std::unique_ptr<tAO> analogOutputSystem;
|
||||
extern std::mutex analogRegisterWindowMutex;
|
||||
extern wpi::mutex analogRegisterWindowMutex;
|
||||
extern bool analogSampleRateSet;
|
||||
|
||||
struct AnalogPort {
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
using namespace hal;
|
||||
|
||||
// Create a mutex to protect changes to the digital output values
|
||||
static std::mutex digitalDIOMutex;
|
||||
static wpi::mutex digitalDIOMutex;
|
||||
|
||||
static LimitedHandleResource<HAL_DigitalPWMHandle, uint8_t,
|
||||
kNumDigitalPWMOutputs, HAL_HandleEnum::DigitalPWM>
|
||||
@@ -54,7 +54,7 @@ HAL_DigitalHandle HAL_InitializeDIOPort(HAL_PortHandle portHandle,
|
||||
|
||||
port->channel = static_cast<uint8_t>(channel);
|
||||
|
||||
std::lock_guard<std::mutex> sync(digitalDIOMutex);
|
||||
std::lock_guard<wpi::mutex> sync(digitalDIOMutex);
|
||||
|
||||
tDIO::tOutputEnable outputEnable = digitalSystem->readOutputEnable(status);
|
||||
|
||||
@@ -115,7 +115,7 @@ void HAL_FreeDIOPort(HAL_DigitalHandle dioPortHandle) {
|
||||
digitalChannelHandles.Free(dioPortHandle, HAL_HandleEnum::DIO);
|
||||
if (port == nullptr) return;
|
||||
int32_t status = 0;
|
||||
std::lock_guard<std::mutex> sync(digitalDIOMutex);
|
||||
std::lock_guard<wpi::mutex> sync(digitalDIOMutex);
|
||||
if (port->channel >= kNumDigitalHeaders + kNumDigitalMXPChannels) {
|
||||
// Unset the SPI flag
|
||||
int32_t bitToUnset = 1 << remapSPIChannel(port->channel);
|
||||
@@ -205,7 +205,7 @@ void HAL_SetDigitalPWMDutyCycle(HAL_DigitalPWMHandle pwmGenerator,
|
||||
double rawDutyCycle = 256.0 * dutyCycle;
|
||||
if (rawDutyCycle > 255.5) rawDutyCycle = 255.5;
|
||||
{
|
||||
std::lock_guard<std::mutex> sync(digitalPwmMutex);
|
||||
std::lock_guard<wpi::mutex> sync(digitalPwmMutex);
|
||||
uint16_t pwmPeriodPower = digitalSystem->readPWMPeriodPower(status);
|
||||
if (pwmPeriodPower < 4) {
|
||||
// The resolution of the duty cycle drops close to the highest
|
||||
@@ -265,7 +265,7 @@ void HAL_SetDIO(HAL_DigitalHandle dioPortHandle, HAL_Bool value,
|
||||
if (value != 0) value = 1;
|
||||
}
|
||||
{
|
||||
std::lock_guard<std::mutex> sync(digitalDIOMutex);
|
||||
std::lock_guard<wpi::mutex> sync(digitalDIOMutex);
|
||||
tDIO::tDO currentDIO = digitalSystem->readDO(status);
|
||||
|
||||
if (port->channel >= kNumDigitalHeaders + kNumDigitalMXPChannels) {
|
||||
@@ -437,7 +437,7 @@ void HAL_SetFilterSelect(HAL_DigitalHandle dioPortHandle, int32_t filterIndex,
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> sync(digitalDIOMutex);
|
||||
std::lock_guard<wpi::mutex> sync(digitalDIOMutex);
|
||||
if (port->channel >= kNumDigitalHeaders + kNumDigitalMXPChannels) {
|
||||
// Channels 10-15 are SPI channels, so subtract our MXP channels
|
||||
digitalSystem->writeFilterSelectHdr(port->channel - kNumDigitalMXPChannels,
|
||||
@@ -465,7 +465,7 @@ int32_t HAL_GetFilterSelect(HAL_DigitalHandle dioPortHandle, int32_t* status) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> sync(digitalDIOMutex);
|
||||
std::lock_guard<wpi::mutex> sync(digitalDIOMutex);
|
||||
if (port->channel >= kNumDigitalHeaders + kNumDigitalMXPChannels) {
|
||||
// Channels 10-15 are SPI channels, so subtract our MXP channels
|
||||
return digitalSystem->readFilterSelectHdr(
|
||||
@@ -492,7 +492,7 @@ int32_t HAL_GetFilterSelect(HAL_DigitalHandle dioPortHandle, int32_t* status) {
|
||||
void HAL_SetFilterPeriod(int32_t filterIndex, int64_t value, int32_t* status) {
|
||||
initializeDigital(status);
|
||||
if (*status != 0) return;
|
||||
std::lock_guard<std::mutex> sync(digitalDIOMutex);
|
||||
std::lock_guard<wpi::mutex> sync(digitalDIOMutex);
|
||||
digitalSystem->writeFilterPeriodHdr(filterIndex, value, status);
|
||||
if (*status == 0) {
|
||||
digitalSystem->writeFilterPeriodMXP(filterIndex, value, status);
|
||||
@@ -517,7 +517,7 @@ int64_t HAL_GetFilterPeriod(int32_t filterIndex, int32_t* status) {
|
||||
uint32_t hdrPeriod = 0;
|
||||
uint32_t mxpPeriod = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> sync(digitalDIOMutex);
|
||||
std::lock_guard<wpi::mutex> sync(digitalDIOMutex);
|
||||
hdrPeriod = digitalSystem->readFilterPeriodHdr(filterIndex, status);
|
||||
if (*status == 0) {
|
||||
mxpPeriod = digitalSystem->readFilterPeriodMXP(filterIndex, status);
|
||||
|
||||
@@ -8,10 +8,10 @@
|
||||
#include "DigitalInternal.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
|
||||
#include <FRC_NetworkCommunication/LoadOut.h>
|
||||
#include <support/mutex.h>
|
||||
|
||||
#include "ConstantsInternal.h"
|
||||
#include "HAL/AnalogTrigger.h"
|
||||
@@ -23,7 +23,7 @@
|
||||
namespace hal {
|
||||
|
||||
// Create a mutex to protect changes to the DO PWM config
|
||||
std::mutex digitalPwmMutex;
|
||||
wpi::mutex digitalPwmMutex;
|
||||
|
||||
std::unique_ptr<tDIO> digitalSystem;
|
||||
std::unique_ptr<tRelay> relaySystem;
|
||||
@@ -31,7 +31,7 @@ std::unique_ptr<tPWM> pwmSystem;
|
||||
std::unique_ptr<tSPI> spiSystem;
|
||||
|
||||
static std::atomic<bool> digitalSystemsInitialized{false};
|
||||
static std::mutex initializeMutex;
|
||||
static wpi::mutex initializeMutex;
|
||||
|
||||
DigitalHandleResource<HAL_DigitalHandle, DigitalPort,
|
||||
kNumDigitalChannels + kNumPWMHeaders>
|
||||
@@ -44,7 +44,7 @@ void initializeDigital(int32_t* status) {
|
||||
// Initial check, as if it's true initialization has finished
|
||||
if (digitalSystemsInitialized) return;
|
||||
|
||||
std::lock_guard<std::mutex> lock(initializeMutex);
|
||||
std::lock_guard<wpi::mutex> lock(initializeMutex);
|
||||
// Second check in case another thread was waiting
|
||||
if (digitalSystemsInitialized) return;
|
||||
|
||||
|
||||
@@ -10,7 +10,8 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
#include <support/mutex.h>
|
||||
|
||||
#include "HAL/AnalogTrigger.h"
|
||||
#include "HAL/ChipObject.h"
|
||||
@@ -59,7 +60,7 @@ constexpr int32_t kDefaultPwmStepsDown = 1000;
|
||||
constexpr int32_t kPwmDisabled = 0;
|
||||
|
||||
// Create a mutex to protect changes to the DO PWM config
|
||||
extern std::mutex digitalPwmMutex;
|
||||
extern wpi::mutex digitalPwmMutex;
|
||||
|
||||
extern std::unique_ptr<tDIO> digitalSystem;
|
||||
extern std::unique_ptr<tRelay> relaySystem;
|
||||
|
||||
@@ -7,15 +7,15 @@
|
||||
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <condition_variable>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <limits>
|
||||
#include <mutex>
|
||||
|
||||
#include <FRC_NetworkCommunication/FRCComm.h>
|
||||
#include <FRC_NetworkCommunication/NetCommRPCProxy_Occur.h>
|
||||
#include <llvm/raw_ostream.h>
|
||||
#include <support/condition_variable.h>
|
||||
#include <support/mutex.h>
|
||||
|
||||
#include "HAL/DriverStation.h"
|
||||
|
||||
@@ -27,9 +27,9 @@ struct HAL_JoystickAxesInt {
|
||||
int16_t axes[HAL_kMaxJoystickAxes];
|
||||
};
|
||||
|
||||
static std::mutex msgMutex;
|
||||
static std::condition_variable newDSDataAvailableCond;
|
||||
static std::mutex newDSDataAvailableMutex;
|
||||
static wpi::mutex msgMutex;
|
||||
static wpi::condition_variable newDSDataAvailableCond;
|
||||
static wpi::mutex newDSDataAvailableMutex;
|
||||
static int newDSDataAvailableCounter{0};
|
||||
|
||||
extern "C" {
|
||||
@@ -40,7 +40,7 @@ int32_t HAL_SendError(HAL_Bool isError, int32_t errorCode, HAL_Bool isLVCode,
|
||||
// Avoid flooding console by keeping track of previous 5 error
|
||||
// messages and only printing again if they're longer than 1 second old.
|
||||
static constexpr int KEEP_MSGS = 5;
|
||||
std::lock_guard<std::mutex> lock(msgMutex);
|
||||
std::lock_guard<wpi::mutex> lock(msgMutex);
|
||||
static std::string prevMsg[KEEP_MSGS];
|
||||
static std::chrono::time_point<std::chrono::steady_clock>
|
||||
prevMsgTime[KEEP_MSGS];
|
||||
@@ -315,7 +315,7 @@ bool HAL_IsNewControlData(void) {
|
||||
thread_local int lastCount{-1};
|
||||
int currentCount = 0;
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(newDSDataAvailableMutex);
|
||||
std::unique_lock<wpi::mutex> lock(newDSDataAvailableMutex);
|
||||
currentCount = newDSDataAvailableCounter;
|
||||
}
|
||||
if (lastCount == currentCount) return false;
|
||||
@@ -337,7 +337,7 @@ HAL_Bool HAL_WaitForDSDataTimeout(double timeout) {
|
||||
auto timeoutTime =
|
||||
std::chrono::steady_clock::now() + std::chrono::duration<double>(timeout);
|
||||
|
||||
std::unique_lock<std::mutex> lock(newDSDataAvailableMutex);
|
||||
std::unique_lock<wpi::mutex> lock(newDSDataAvailableMutex);
|
||||
int currentCount = newDSDataAvailableCounter;
|
||||
while (newDSDataAvailableCounter == currentCount) {
|
||||
if (timeout > 0) {
|
||||
@@ -359,7 +359,7 @@ static void newDataOccur(uint32_t refNum) {
|
||||
// Since we could get other values, require our specific handle
|
||||
// to signal our threads
|
||||
if (refNum != refNumber) return;
|
||||
std::lock_guard<std::mutex> lock(newDSDataAvailableMutex);
|
||||
std::lock_guard<wpi::mutex> lock(newDSDataAvailableMutex);
|
||||
// Nofify all threads
|
||||
newDSDataAvailableCounter++;
|
||||
newDSDataAvailableCond.notify_all();
|
||||
@@ -372,11 +372,11 @@ static void newDataOccur(uint32_t refNum) {
|
||||
*/
|
||||
void HAL_InitializeDriverStation(void) {
|
||||
static std::atomic_bool initialized{false};
|
||||
static std::mutex initializeMutex;
|
||||
static wpi::mutex initializeMutex;
|
||||
// Initial check, as if it's true initialization has finished
|
||||
if (initialized) return;
|
||||
|
||||
std::lock_guard<std::mutex> lock(initializeMutex);
|
||||
std::lock_guard<wpi::mutex> lock(initializeMutex);
|
||||
// Second check in case another thread was waiting
|
||||
if (initialized) return;
|
||||
|
||||
|
||||
@@ -14,12 +14,12 @@
|
||||
#include <atomic>
|
||||
#include <cstdlib>
|
||||
#include <fstream>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
|
||||
#include <FRC_NetworkCommunication/FRCComm.h>
|
||||
#include <FRC_NetworkCommunication/LoadOut.h>
|
||||
#include <llvm/raw_ostream.h>
|
||||
#include <support/mutex.h>
|
||||
|
||||
#include "HAL/ChipObject.h"
|
||||
#include "HAL/DriverStation.h"
|
||||
@@ -261,11 +261,11 @@ HAL_Bool HAL_GetBrownedOut(int32_t* status) {
|
||||
|
||||
void HAL_BaseInitialize(int32_t* status) {
|
||||
static std::atomic_bool initialized{false};
|
||||
static std::mutex initializeMutex;
|
||||
static wpi::mutex initializeMutex;
|
||||
// Initial check, as if it's true initialization has finished
|
||||
if (initialized) return;
|
||||
|
||||
std::lock_guard<std::mutex> lock(initializeMutex);
|
||||
std::lock_guard<wpi::mutex> lock(initializeMutex);
|
||||
// Second check in case another thread was waiting
|
||||
if (initialized) return;
|
||||
// image 4; Fixes errors caused by multiple processes. Talk to NI about this
|
||||
@@ -323,11 +323,11 @@ static bool killExistingProgram(int timeout, int mode) {
|
||||
*/
|
||||
HAL_Bool HAL_Initialize(int32_t timeout, int32_t mode) {
|
||||
static std::atomic_bool initialized{false};
|
||||
static std::mutex initializeMutex;
|
||||
static wpi::mutex initializeMutex;
|
||||
// Initial check, as if it's true initialization has finished
|
||||
if (initialized) return true;
|
||||
|
||||
std::lock_guard<std::mutex> lock(initializeMutex);
|
||||
std::lock_guard<wpi::mutex> lock(initializeMutex);
|
||||
// Second check in case another thread was waiting
|
||||
if (initialized) return true;
|
||||
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
|
||||
using namespace hal;
|
||||
|
||||
static std::mutex digitalI2COnBoardMutex;
|
||||
static std::mutex digitalI2CMXPMutex;
|
||||
static wpi::mutex digitalI2COnBoardMutex;
|
||||
static wpi::mutex digitalI2CMXPMutex;
|
||||
|
||||
static uint8_t i2COnboardObjCount = 0;
|
||||
static uint8_t i2CMXPObjCount = 0;
|
||||
@@ -42,9 +42,9 @@ void HAL_InitializeI2C(HAL_I2CPort port, int32_t* status) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::mutex& lock = port == 0 ? digitalI2COnBoardMutex : digitalI2CMXPMutex;
|
||||
wpi::mutex& lock = port == 0 ? digitalI2COnBoardMutex : digitalI2CMXPMutex;
|
||||
{
|
||||
std::lock_guard<std::mutex> sync(lock);
|
||||
std::lock_guard<wpi::mutex> sync(lock);
|
||||
if (port == 0) {
|
||||
i2COnboardObjCount++;
|
||||
if (i2COnBoardHandle > 0) return;
|
||||
@@ -90,10 +90,10 @@ int32_t HAL_TransactionI2C(HAL_I2CPort port, int32_t deviceAddress,
|
||||
}
|
||||
|
||||
int32_t handle = port == 0 ? i2COnBoardHandle : i2CMXPHandle;
|
||||
std::mutex& lock = port == 0 ? digitalI2COnBoardMutex : digitalI2CMXPMutex;
|
||||
wpi::mutex& lock = port == 0 ? digitalI2COnBoardMutex : digitalI2CMXPMutex;
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> sync(lock);
|
||||
std::lock_guard<wpi::mutex> sync(lock);
|
||||
return i2clib_writeread(
|
||||
handle, deviceAddress, reinterpret_cast<const char*>(dataToSend),
|
||||
static_cast<int32_t>(sendSize), reinterpret_cast<char*>(dataReceived),
|
||||
@@ -120,9 +120,9 @@ int32_t HAL_WriteI2C(HAL_I2CPort port, int32_t deviceAddress,
|
||||
}
|
||||
|
||||
int32_t handle = port == 0 ? i2COnBoardHandle : i2CMXPHandle;
|
||||
std::mutex& lock = port == 0 ? digitalI2COnBoardMutex : digitalI2CMXPMutex;
|
||||
wpi::mutex& lock = port == 0 ? digitalI2COnBoardMutex : digitalI2CMXPMutex;
|
||||
{
|
||||
std::lock_guard<std::mutex> sync(lock);
|
||||
std::lock_guard<wpi::mutex> sync(lock);
|
||||
return i2clib_write(handle, deviceAddress,
|
||||
reinterpret_cast<const char*>(dataToSend), sendSize);
|
||||
}
|
||||
@@ -149,9 +149,9 @@ int32_t HAL_ReadI2C(HAL_I2CPort port, int32_t deviceAddress, uint8_t* buffer,
|
||||
}
|
||||
|
||||
int32_t handle = port == 0 ? i2COnBoardHandle : i2CMXPHandle;
|
||||
std::mutex& lock = port == 0 ? digitalI2COnBoardMutex : digitalI2CMXPMutex;
|
||||
wpi::mutex& lock = port == 0 ? digitalI2COnBoardMutex : digitalI2CMXPMutex;
|
||||
{
|
||||
std::lock_guard<std::mutex> sync(lock);
|
||||
std::lock_guard<wpi::mutex> sync(lock);
|
||||
return i2clib_read(handle, deviceAddress, reinterpret_cast<char*>(buffer),
|
||||
static_cast<int32_t>(count));
|
||||
}
|
||||
@@ -162,9 +162,9 @@ void HAL_CloseI2C(HAL_I2CPort port) {
|
||||
// Set port out of range error here
|
||||
return;
|
||||
}
|
||||
std::mutex& lock = port == 0 ? digitalI2COnBoardMutex : digitalI2CMXPMutex;
|
||||
wpi::mutex& lock = port == 0 ? digitalI2COnBoardMutex : digitalI2CMXPMutex;
|
||||
{
|
||||
std::lock_guard<std::mutex> sync(lock);
|
||||
std::lock_guard<wpi::mutex> sync(lock);
|
||||
if ((port == 0 ? i2COnboardObjCount-- : i2CMXPObjCount--) == 0) {
|
||||
int32_t handle = port == 0 ? i2COnBoardHandle : i2CMXPHandle;
|
||||
i2clib_close(handle);
|
||||
|
||||
@@ -32,7 +32,7 @@ struct Interrupt {
|
||||
class InterruptThread : public wpi::SafeThread {
|
||||
public:
|
||||
void Main() {
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
std::unique_lock<wpi::mutex> lock(m_mutex);
|
||||
while (m_active) {
|
||||
m_cond.wait(lock, [&] { return !m_active || m_notify; });
|
||||
if (!m_active) break;
|
||||
|
||||
@@ -10,9 +10,9 @@
|
||||
#include <atomic>
|
||||
#include <cstdlib> // For std::atexit()
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
#include <support/SafeThread.h>
|
||||
#include <support/mutex.h>
|
||||
|
||||
#include "HAL/ChipObject.h"
|
||||
#include "HAL/Errors.h"
|
||||
@@ -25,8 +25,8 @@ using namespace hal;
|
||||
|
||||
static const int32_t kTimerInterruptNumber = 28;
|
||||
|
||||
static std::mutex notifierInterruptMutex;
|
||||
static std::mutex notifierMutex;
|
||||
static wpi::mutex notifierInterruptMutex;
|
||||
static wpi::mutex notifierMutex;
|
||||
static std::unique_ptr<tAlarm> notifierAlarm;
|
||||
static std::unique_ptr<tInterruptManager> notifierManager;
|
||||
static uint64_t closestTrigger = UINT64_MAX;
|
||||
@@ -46,7 +46,7 @@ struct Notifier {
|
||||
class NotifierThread : public wpi::SafeThread {
|
||||
public:
|
||||
void Main() {
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
std::unique_lock<wpi::mutex> lock(m_mutex);
|
||||
while (m_active) {
|
||||
m_cond.wait(lock, [&] { return !m_active || m_notify; });
|
||||
if (!m_active) break;
|
||||
@@ -126,7 +126,7 @@ void updateNotifierAlarmInternal(std::shared_ptr<Notifier> notifierPointer,
|
||||
}
|
||||
|
||||
static void alarmCallback(uint32_t, void*) {
|
||||
std::unique_lock<std::mutex> sync(notifierMutex);
|
||||
std::unique_lock<wpi::mutex> sync(notifierMutex);
|
||||
|
||||
int32_t status = 0;
|
||||
uint64_t currentTime = 0;
|
||||
@@ -182,7 +182,7 @@ HAL_NotifierHandle HAL_InitializeNotifierNonThreadedUnsafe(
|
||||
if (!notifierAtexitRegistered.test_and_set())
|
||||
std::atexit(cleanupNotifierAtExit);
|
||||
if (notifierRefCount.fetch_add(1) == 0) {
|
||||
std::lock_guard<std::mutex> sync(notifierInterruptMutex);
|
||||
std::lock_guard<wpi::mutex> sync(notifierInterruptMutex);
|
||||
// create manager and alarm if not already created
|
||||
if (!notifierManager) {
|
||||
notifierManager = std::make_unique<tInterruptManager>(
|
||||
@@ -193,7 +193,7 @@ HAL_NotifierHandle HAL_InitializeNotifierNonThreadedUnsafe(
|
||||
if (!notifierAlarm) notifierAlarm.reset(tAlarm::create(status));
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> sync(notifierMutex);
|
||||
std::lock_guard<wpi::mutex> sync(notifierMutex);
|
||||
std::shared_ptr<Notifier> notifier = std::make_shared<Notifier>();
|
||||
HAL_NotifierHandle handle = notifierHandles.Allocate(notifier);
|
||||
if (handle == HAL_kInvalidHandle) {
|
||||
@@ -236,7 +236,7 @@ HAL_NotifierHandle HAL_InitializeNotifier(HAL_NotifierProcessFunction process,
|
||||
|
||||
void HAL_CleanNotifier(HAL_NotifierHandle notifierHandle, int32_t* status) {
|
||||
{
|
||||
std::lock_guard<std::mutex> sync(notifierMutex);
|
||||
std::lock_guard<wpi::mutex> sync(notifierMutex);
|
||||
auto notifier = notifierHandles.Get(notifierHandle);
|
||||
if (!notifier) return;
|
||||
|
||||
@@ -254,7 +254,7 @@ void HAL_CleanNotifier(HAL_NotifierHandle notifierHandle, int32_t* status) {
|
||||
}
|
||||
|
||||
if (notifierRefCount.fetch_sub(1) == 1) {
|
||||
std::lock_guard<std::mutex> sync(notifierInterruptMutex);
|
||||
std::lock_guard<wpi::mutex> sync(notifierInterruptMutex);
|
||||
// if this was the last notifier, clean up alarm and manager
|
||||
if (notifierAlarm) {
|
||||
notifierAlarm->writeEnable(false, status);
|
||||
@@ -282,7 +282,7 @@ void* HAL_GetNotifierParam(HAL_NotifierHandle notifierHandle, int32_t* status) {
|
||||
|
||||
void HAL_UpdateNotifierAlarm(HAL_NotifierHandle notifierHandle,
|
||||
uint64_t triggerTime, int32_t* status) {
|
||||
std::lock_guard<std::mutex> sync(notifierMutex);
|
||||
std::lock_guard<wpi::mutex> sync(notifierMutex);
|
||||
|
||||
auto notifier = notifierHandles.Get(notifierHandle);
|
||||
if (!notifier) return;
|
||||
@@ -290,7 +290,7 @@ void HAL_UpdateNotifierAlarm(HAL_NotifierHandle notifierHandle,
|
||||
}
|
||||
|
||||
void HAL_StopNotifierAlarm(HAL_NotifierHandle notifierHandle, int32_t* status) {
|
||||
std::lock_guard<std::mutex> sync(notifierMutex);
|
||||
std::lock_guard<wpi::mutex> sync(notifierMutex);
|
||||
auto notifier = notifierHandles.Get(notifierHandle);
|
||||
if (!notifier) return;
|
||||
notifier->triggerTime = UINT64_MAX;
|
||||
|
||||
@@ -27,7 +27,7 @@ static IndexedHandleResource<HAL_RelayHandle, Relay, kNumRelayChannels,
|
||||
relayHandles;
|
||||
|
||||
// Create a mutex to protect changes to the relay values
|
||||
static std::mutex digitalRelayMutex;
|
||||
static wpi::mutex digitalRelayMutex;
|
||||
|
||||
extern "C" {
|
||||
|
||||
@@ -92,7 +92,7 @@ void HAL_SetRelay(HAL_RelayHandle relayPortHandle, HAL_Bool on,
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
std::lock_guard<std::mutex> sync(digitalRelayMutex);
|
||||
std::lock_guard<wpi::mutex> sync(digitalRelayMutex);
|
||||
uint8_t relays = 0;
|
||||
if (port->fwd) {
|
||||
relays = relaySystem->readValue_Forward(status);
|
||||
|
||||
@@ -9,10 +9,10 @@
|
||||
|
||||
#include <array>
|
||||
#include <atomic>
|
||||
#include <mutex>
|
||||
|
||||
#include <llvm/raw_ostream.h>
|
||||
#include <spilib/spi-lib.h>
|
||||
#include <support/mutex.h>
|
||||
|
||||
#include "DigitalInternal.h"
|
||||
#include "HAL/DIO.h"
|
||||
@@ -32,9 +32,9 @@ static int32_t m_spiMXPHandle = 0;
|
||||
static constexpr int32_t kSpiMaxHandles = 5;
|
||||
|
||||
// Indices 0-3 are for onboard CS0-CS2. Index 4 is for MXP.
|
||||
static std::array<std::mutex, kSpiMaxHandles> spiHandleMutexes;
|
||||
static std::array<std::mutex, kSpiMaxHandles> spiApiMutexes;
|
||||
static std::array<std::mutex, kSpiMaxHandles> spiAccumulatorMutexes;
|
||||
static std::array<wpi::mutex, kSpiMaxHandles> spiHandleMutexes;
|
||||
static std::array<wpi::mutex, kSpiMaxHandles> spiApiMutexes;
|
||||
static std::array<wpi::mutex, kSpiMaxHandles> spiAccumulatorMutexes;
|
||||
|
||||
// MXP SPI does not count towards this
|
||||
std::atomic<int32_t> spiPortCount{0};
|
||||
@@ -220,7 +220,7 @@ int32_t HAL_TransactionSPI(HAL_SPIPort port, uint8_t* dataToSend,
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> sync(spiApiMutexes[port]);
|
||||
std::lock_guard<wpi::mutex> sync(spiApiMutexes[port]);
|
||||
return spilib_writeread(
|
||||
HAL_GetSPIHandle(port), reinterpret_cast<const char*>(dataToSend),
|
||||
reinterpret_cast<char*>(dataReceived), static_cast<int32_t>(size));
|
||||
@@ -241,7 +241,7 @@ int32_t HAL_WriteSPI(HAL_SPIPort port, uint8_t* dataToSend, int32_t sendSize) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> sync(spiApiMutexes[port]);
|
||||
std::lock_guard<wpi::mutex> sync(spiApiMutexes[port]);
|
||||
return spilib_write(HAL_GetSPIHandle(port),
|
||||
reinterpret_cast<const char*>(dataToSend),
|
||||
static_cast<int32_t>(sendSize));
|
||||
@@ -265,7 +265,7 @@ int32_t HAL_ReadSPI(HAL_SPIPort port, uint8_t* buffer, int32_t count) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> sync(spiApiMutexes[port]);
|
||||
std::lock_guard<wpi::mutex> sync(spiApiMutexes[port]);
|
||||
return spilib_read(HAL_GetSPIHandle(port), reinterpret_cast<char*>(buffer),
|
||||
static_cast<int32_t>(count));
|
||||
}
|
||||
@@ -284,7 +284,7 @@ void HAL_CloseSPI(HAL_SPIPort port) {
|
||||
HAL_FreeSPIAccumulator(port, &status);
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> sync(spiApiMutexes[port]);
|
||||
std::lock_guard<wpi::mutex> sync(spiApiMutexes[port]);
|
||||
spilib_close(HAL_GetSPIHandle(port));
|
||||
}
|
||||
|
||||
@@ -326,7 +326,7 @@ void HAL_SetSPISpeed(HAL_SPIPort port, int32_t speed) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> sync(spiApiMutexes[port]);
|
||||
std::lock_guard<wpi::mutex> sync(spiApiMutexes[port]);
|
||||
spilib_setspeed(HAL_GetSPIHandle(port), speed);
|
||||
}
|
||||
|
||||
@@ -346,7 +346,7 @@ void HAL_SetSPIOpts(HAL_SPIPort port, HAL_Bool msbFirst,
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> sync(spiApiMutexes[port]);
|
||||
std::lock_guard<wpi::mutex> sync(spiApiMutexes[port]);
|
||||
spilib_setopts(HAL_GetSPIHandle(port), msbFirst, sampleOnTrailing,
|
||||
clkIdleHigh);
|
||||
}
|
||||
@@ -362,7 +362,7 @@ void HAL_SetSPIChipSelectActiveHigh(HAL_SPIPort port, int32_t* status) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> sync(spiApiMutexes[port]);
|
||||
std::lock_guard<wpi::mutex> sync(spiApiMutexes[port]);
|
||||
if (port < 4) {
|
||||
spiSystem->writeChipSelectActiveHigh_Hdr(
|
||||
spiSystem->readChipSelectActiveHigh_Hdr(status) | (1 << port), status);
|
||||
@@ -382,7 +382,7 @@ void HAL_SetSPIChipSelectActiveLow(HAL_SPIPort port, int32_t* status) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> sync(spiApiMutexes[port]);
|
||||
std::lock_guard<wpi::mutex> sync(spiApiMutexes[port]);
|
||||
if (port < 4) {
|
||||
spiSystem->writeChipSelectActiveHigh_Hdr(
|
||||
spiSystem->readChipSelectActiveHigh_Hdr(status) & ~(1 << port), status);
|
||||
@@ -402,7 +402,7 @@ int32_t HAL_GetSPIHandle(HAL_SPIPort port) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> sync(spiHandleMutexes[port]);
|
||||
std::lock_guard<wpi::mutex> sync(spiHandleMutexes[port]);
|
||||
switch (port) {
|
||||
case 0:
|
||||
return m_spiCS0Handle;
|
||||
@@ -431,7 +431,7 @@ void HAL_SetSPIHandle(HAL_SPIPort port, int32_t handle) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> sync(spiHandleMutexes[port]);
|
||||
std::lock_guard<wpi::mutex> sync(spiHandleMutexes[port]);
|
||||
switch (port) {
|
||||
case 0:
|
||||
m_spiCS0Handle = handle;
|
||||
@@ -463,7 +463,7 @@ static void spiAccumulatorProcess(uint64_t currentTime,
|
||||
// perform SPI transaction
|
||||
uint8_t resp_b[4];
|
||||
{
|
||||
std::lock_guard<std::mutex> sync(spiApiMutexes[accum->port]);
|
||||
std::lock_guard<wpi::mutex> sync(spiApiMutexes[accum->port]);
|
||||
spilib_writeread(HAL_GetSPIHandle(accum->port),
|
||||
reinterpret_cast<const char*>(accum->cmd),
|
||||
reinterpret_cast<char*>(resp_b),
|
||||
@@ -538,7 +538,7 @@ void HAL_InitSPIAccumulator(HAL_SPIPort port, int32_t period, int32_t cmd,
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> sync(spiAccumulatorMutexes[port]);
|
||||
std::lock_guard<wpi::mutex> sync(spiAccumulatorMutexes[port]);
|
||||
if (!spiAccumulators[port])
|
||||
spiAccumulators[port] = std::make_unique<SPIAccumulator>();
|
||||
SPIAccumulator* accum = spiAccumulators[port].get();
|
||||
@@ -584,7 +584,7 @@ void HAL_FreeSPIAccumulator(HAL_SPIPort port, int32_t* status) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> sync(spiAccumulatorMutexes[port]);
|
||||
std::lock_guard<wpi::mutex> sync(spiAccumulatorMutexes[port]);
|
||||
SPIAccumulator* accum = spiAccumulators[port].get();
|
||||
if (!accum) {
|
||||
*status = NULL_PARAMETER;
|
||||
@@ -604,7 +604,7 @@ void HAL_ResetSPIAccumulator(HAL_SPIPort port, int32_t* status) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> sync(spiApiMutexes[port]);
|
||||
std::lock_guard<wpi::mutex> sync(spiApiMutexes[port]);
|
||||
SPIAccumulator* accum = spiAccumulators[port].get();
|
||||
if (!accum) {
|
||||
*status = NULL_PARAMETER;
|
||||
@@ -631,7 +631,7 @@ void HAL_SetSPIAccumulatorCenter(HAL_SPIPort port, int32_t center,
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> sync(spiAccumulatorMutexes[port]);
|
||||
std::lock_guard<wpi::mutex> sync(spiAccumulatorMutexes[port]);
|
||||
SPIAccumulator* accum = spiAccumulators[port].get();
|
||||
if (!accum) {
|
||||
*status = NULL_PARAMETER;
|
||||
@@ -650,7 +650,7 @@ void HAL_SetSPIAccumulatorDeadband(HAL_SPIPort port, int32_t deadband,
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> sync(spiAccumulatorMutexes[port]);
|
||||
std::lock_guard<wpi::mutex> sync(spiAccumulatorMutexes[port]);
|
||||
SPIAccumulator* accum = spiAccumulators[port].get();
|
||||
if (!accum) {
|
||||
*status = NULL_PARAMETER;
|
||||
@@ -668,7 +668,7 @@ int32_t HAL_GetSPIAccumulatorLastValue(HAL_SPIPort port, int32_t* status) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> sync(spiAccumulatorMutexes[port]);
|
||||
std::lock_guard<wpi::mutex> sync(spiAccumulatorMutexes[port]);
|
||||
SPIAccumulator* accum = spiAccumulators[port].get();
|
||||
if (!accum) {
|
||||
*status = NULL_PARAMETER;
|
||||
@@ -688,7 +688,7 @@ int64_t HAL_GetSPIAccumulatorValue(HAL_SPIPort port, int32_t* status) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> sync(spiAccumulatorMutexes[port]);
|
||||
std::lock_guard<wpi::mutex> sync(spiAccumulatorMutexes[port]);
|
||||
SPIAccumulator* accum = spiAccumulators[port].get();
|
||||
if (!accum) {
|
||||
*status = NULL_PARAMETER;
|
||||
@@ -711,7 +711,7 @@ int64_t HAL_GetSPIAccumulatorCount(HAL_SPIPort port, int32_t* status) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> sync(spiAccumulatorMutexes[port]);
|
||||
std::lock_guard<wpi::mutex> sync(spiAccumulatorMutexes[port]);
|
||||
SPIAccumulator* accum = spiAccumulators[port].get();
|
||||
if (!accum) {
|
||||
*status = NULL_PARAMETER;
|
||||
@@ -754,7 +754,7 @@ void HAL_GetSPIAccumulatorOutput(HAL_SPIPort port, int64_t* value,
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> sync(spiAccumulatorMutexes[port]);
|
||||
std::lock_guard<wpi::mutex> sync(spiAccumulatorMutexes[port]);
|
||||
SPIAccumulator* accum = spiAccumulators[port].get();
|
||||
if (!accum) {
|
||||
*status = NULL_PARAMETER;
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace hal {
|
||||
|
||||
std::string SerialHelper::m_usbNames[2]{"", ""};
|
||||
|
||||
std::mutex SerialHelper::m_nameMutex;
|
||||
wpi::mutex SerialHelper::m_nameMutex;
|
||||
|
||||
SerialHelper::SerialHelper() {
|
||||
viOpenDefaultRM(reinterpret_cast<ViSession*>(&m_resourceHandle));
|
||||
@@ -273,7 +273,7 @@ done:
|
||||
|
||||
int32_t SerialHelper::GetIndexForPort(HAL_SerialPort port, int32_t* status) {
|
||||
// Hold lock whenever we're using the names array
|
||||
std::lock_guard<std::mutex> lock(m_nameMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_nameMutex);
|
||||
|
||||
std::string portString = m_usbNames[port - 2];
|
||||
|
||||
|
||||
@@ -9,12 +9,12 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <llvm/SmallString.h>
|
||||
#include <llvm/SmallVector.h>
|
||||
#include <support/mutex.h>
|
||||
|
||||
#include "HAL/SerialPort.h"
|
||||
|
||||
@@ -46,7 +46,7 @@ class SerialHelper {
|
||||
|
||||
int32_t m_resourceHandle;
|
||||
|
||||
static std::mutex m_nameMutex;
|
||||
static wpi::mutex m_nameMutex;
|
||||
static std::string m_usbNames[2];
|
||||
};
|
||||
} // namespace hal
|
||||
|
||||
@@ -1,92 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2017 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
// Allows usage with std::lock_guard without including <mutex> separately
|
||||
#include <mutex>
|
||||
|
||||
#if !defined(__linux__)
|
||||
namespace hal {
|
||||
// We do not want to use pthreads if in the simulator; however, in the
|
||||
// simulator, we do not care about priority inversion.
|
||||
typedef std::mutex priority_mutex;
|
||||
typedef std::recursive_mutex priority_recursive_mutex;
|
||||
} // namespace hal
|
||||
#else // Covers rest of file.
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
namespace hal {
|
||||
|
||||
class priority_recursive_mutex {
|
||||
public:
|
||||
typedef pthread_mutex_t* native_handle_type;
|
||||
|
||||
constexpr priority_recursive_mutex() noexcept = default;
|
||||
priority_recursive_mutex(const priority_recursive_mutex&) = delete;
|
||||
priority_recursive_mutex& operator=(const priority_recursive_mutex&) = delete;
|
||||
|
||||
// Lock the mutex, blocking until it's available.
|
||||
void lock();
|
||||
|
||||
// Unlock the mutex.
|
||||
void unlock();
|
||||
|
||||
// Tries to lock the mutex.
|
||||
bool try_lock() noexcept;
|
||||
|
||||
pthread_mutex_t* native_handle();
|
||||
|
||||
private:
|
||||
// Do the equivalent of setting PTHREAD_PRIO_INHERIT and
|
||||
// PTHREAD_MUTEX_RECURSIVE_NP.
|
||||
#if __WORDSIZE == 64
|
||||
pthread_mutex_t m_mutex = {
|
||||
{0, 0, 0, 0, 0x20 | PTHREAD_MUTEX_RECURSIVE_NP, 0, 0, {0, 0}}};
|
||||
#else
|
||||
pthread_mutex_t m_mutex = {
|
||||
{0, 0, 0, 0x20 | PTHREAD_MUTEX_RECURSIVE_NP, 0, {0}}};
|
||||
#endif
|
||||
};
|
||||
|
||||
class priority_mutex {
|
||||
public:
|
||||
typedef pthread_mutex_t* native_handle_type;
|
||||
|
||||
constexpr priority_mutex() noexcept = default;
|
||||
priority_mutex(const priority_mutex&) = delete;
|
||||
priority_mutex& operator=(const priority_mutex&) = delete;
|
||||
|
||||
// Lock the mutex, blocking until it's available.
|
||||
void lock();
|
||||
|
||||
// Unlock the mutex.
|
||||
void unlock();
|
||||
|
||||
// Tries to lock the mutex.
|
||||
bool try_lock() noexcept;
|
||||
|
||||
pthread_mutex_t* native_handle();
|
||||
|
||||
private:
|
||||
// Do the equivalent of setting PTHREAD_PRIO_INHERIT.
|
||||
#if __WORDSIZE == 64
|
||||
pthread_mutex_t m_mutex = {{0, 0, 0, 0, 0x20, 0, 0, {0, 0}}};
|
||||
#else
|
||||
pthread_mutex_t m_mutex = {{0, 0, 0, 0x20, 0, {0}}};
|
||||
#endif
|
||||
};
|
||||
} // namespace hal
|
||||
|
||||
#endif // FRC_SIMULATOR
|
||||
|
||||
// For backwards compatibility
|
||||
#ifndef NAMESPACED_PRIORITY
|
||||
using hal::priority_mutex; // NOLINT
|
||||
using hal::priority_recursive_mutex; // NOLINT
|
||||
#endif
|
||||
@@ -11,7 +11,8 @@
|
||||
|
||||
#include <array>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
#include <support/mutex.h>
|
||||
|
||||
#include "HAL/Errors.h"
|
||||
#include "HAL/Types.h"
|
||||
@@ -48,7 +49,7 @@ class DigitalHandleResource : public HandleBase {
|
||||
|
||||
private:
|
||||
std::array<std::shared_ptr<TStruct>, size> m_structures;
|
||||
std::array<std::mutex, size> m_handleMutexes;
|
||||
std::array<wpi::mutex, size> m_handleMutexes;
|
||||
};
|
||||
|
||||
template <typename THandle, typename TStruct, int16_t size>
|
||||
@@ -59,7 +60,7 @@ THandle DigitalHandleResource<THandle, TStruct, size>::Allocate(
|
||||
*status = RESOURCE_OUT_OF_RANGE;
|
||||
return HAL_kInvalidHandle;
|
||||
}
|
||||
std::lock_guard<std::mutex> sync(m_handleMutexes[index]);
|
||||
std::lock_guard<wpi::mutex> sync(m_handleMutexes[index]);
|
||||
// check for allocation, otherwise allocate and return a valid handle
|
||||
if (m_structures[index] != nullptr) {
|
||||
*status = RESOURCE_IS_ALLOCATED;
|
||||
@@ -77,7 +78,7 @@ std::shared_ptr<TStruct> DigitalHandleResource<THandle, TStruct, size>::Get(
|
||||
if (index < 0 || index >= size) {
|
||||
return nullptr;
|
||||
}
|
||||
std::lock_guard<std::mutex> sync(m_handleMutexes[index]);
|
||||
std::lock_guard<wpi::mutex> sync(m_handleMutexes[index]);
|
||||
// return structure. Null will propogate correctly, so no need to manually
|
||||
// check.
|
||||
return m_structures[index];
|
||||
@@ -90,14 +91,14 @@ void DigitalHandleResource<THandle, TStruct, size>::Free(
|
||||
int16_t index = getHandleTypedIndex(handle, enumValue, m_version);
|
||||
if (index < 0 || index >= size) return;
|
||||
// lock and deallocated handle
|
||||
std::lock_guard<std::mutex> sync(m_handleMutexes[index]);
|
||||
std::lock_guard<wpi::mutex> sync(m_handleMutexes[index]);
|
||||
m_structures[index].reset();
|
||||
}
|
||||
|
||||
template <typename THandle, typename TStruct, int16_t size>
|
||||
void DigitalHandleResource<THandle, TStruct, size>::ResetHandles() {
|
||||
for (int i = 0; i < size; i++) {
|
||||
std::lock_guard<std::mutex> sync(m_handleMutexes[i]);
|
||||
std::lock_guard<wpi::mutex> sync(m_handleMutexes[i]);
|
||||
m_structures[i].reset();
|
||||
}
|
||||
HandleBase::ResetHandles();
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include <support/mutex.h>
|
||||
|
||||
#include "HAL/Errors.h"
|
||||
#include "HAL/Types.h"
|
||||
#include "HAL/cpp/make_unique.h"
|
||||
@@ -51,7 +53,7 @@ class IndexedClassedHandleResource : public HandleBase {
|
||||
|
||||
private:
|
||||
std::array<std::shared_ptr<TStruct>[], size> m_structures;
|
||||
std::array<std::mutex[], size> m_handleMutexes;
|
||||
std::array<wpi::mutex[], size> m_handleMutexes;
|
||||
};
|
||||
|
||||
template <typename THandle, typename TStruct, int16_t size,
|
||||
@@ -59,7 +61,7 @@ template <typename THandle, typename TStruct, int16_t size,
|
||||
IndexedClassedHandleResource<THandle, TStruct, size,
|
||||
enumValue>::IndexedClassedHandleResource() {
|
||||
m_structures = std::make_unique<std::shared_ptr<TStruct>[]>(size);
|
||||
m_handleMutexes = std::make_unique<std::mutex[]>(size);
|
||||
m_handleMutexes = std::make_unique<wpi::mutex[]>(size);
|
||||
}
|
||||
|
||||
template <typename THandle, typename TStruct, int16_t size,
|
||||
@@ -72,7 +74,7 @@ IndexedClassedHandleResource<THandle, TStruct, size, enumValue>::Allocate(
|
||||
*status = RESOURCE_OUT_OF_RANGE;
|
||||
return HAL_kInvalidHandle;
|
||||
}
|
||||
std::lock_guard<std::mutex> sync(m_handleMutexes[index]);
|
||||
std::lock_guard<wpi::mutex> sync(m_handleMutexes[index]);
|
||||
// check for allocation, otherwise allocate and return a valid handle
|
||||
if (m_structures[index] != nullptr) {
|
||||
*status = RESOURCE_IS_ALLOCATED;
|
||||
@@ -92,7 +94,7 @@ IndexedClassedHandleResource<THandle, TStruct, size, enumValue>::Get(
|
||||
if (index < 0 || index >= size) {
|
||||
return nullptr;
|
||||
}
|
||||
std::lock_guard<std::mutex> sync(m_handleMutexes[index]);
|
||||
std::lock_guard<wpi::mutex> sync(m_handleMutexes[index]);
|
||||
// return structure. Null will propogate correctly, so no need to manually
|
||||
// check.
|
||||
return m_structures[index];
|
||||
@@ -106,7 +108,7 @@ void IndexedClassedHandleResource<THandle, TStruct, size, enumValue>::Free(
|
||||
int16_t index = getHandleTypedIndex(handle, enumValue, m_version);
|
||||
if (index < 0 || index >= size) return;
|
||||
// lock and deallocated handle
|
||||
std::lock_guard<std::mutex> sync(m_handleMutexes[index]);
|
||||
std::lock_guard<wpi::mutex> sync(m_handleMutexes[index]);
|
||||
m_structures[index].reset();
|
||||
}
|
||||
|
||||
@@ -115,7 +117,7 @@ template <typename THandle, typename TStruct, int16_t size,
|
||||
void IndexedClassedHandleResource<THandle, TStruct, size,
|
||||
enumValue>::ResetHandles() {
|
||||
for (int i = 0; i < size; i++) {
|
||||
std::lock_guard<std::mutex> sync(m_handleMutexes[i]);
|
||||
std::lock_guard<wpi::mutex> sync(m_handleMutexes[i]);
|
||||
m_structures[i].reset();
|
||||
}
|
||||
HandleBase::ResetHandles();
|
||||
|
||||
@@ -11,7 +11,8 @@
|
||||
|
||||
#include <array>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
#include <support/mutex.h>
|
||||
|
||||
#include "HAL/Errors.h"
|
||||
#include "HAL/Types.h"
|
||||
@@ -49,7 +50,7 @@ class IndexedHandleResource : public HandleBase {
|
||||
|
||||
private:
|
||||
std::array<std::shared_ptr<TStruct>, size> m_structures;
|
||||
std::array<std::mutex, size> m_handleMutexes;
|
||||
std::array<wpi::mutex, size> m_handleMutexes;
|
||||
};
|
||||
|
||||
template <typename THandle, typename TStruct, int16_t size,
|
||||
@@ -61,7 +62,7 @@ THandle IndexedHandleResource<THandle, TStruct, size, enumValue>::Allocate(
|
||||
*status = RESOURCE_OUT_OF_RANGE;
|
||||
return HAL_kInvalidHandle;
|
||||
}
|
||||
std::lock_guard<std::mutex> sync(m_handleMutexes[index]);
|
||||
std::lock_guard<wpi::mutex> sync(m_handleMutexes[index]);
|
||||
// check for allocation, otherwise allocate and return a valid handle
|
||||
if (m_structures[index] != nullptr) {
|
||||
*status = RESOURCE_IS_ALLOCATED;
|
||||
@@ -80,7 +81,7 @@ IndexedHandleResource<THandle, TStruct, size, enumValue>::Get(THandle handle) {
|
||||
if (index < 0 || index >= size) {
|
||||
return nullptr;
|
||||
}
|
||||
std::lock_guard<std::mutex> sync(m_handleMutexes[index]);
|
||||
std::lock_guard<wpi::mutex> sync(m_handleMutexes[index]);
|
||||
// return structure. Null will propogate correctly, so no need to manually
|
||||
// check.
|
||||
return m_structures[index];
|
||||
@@ -94,7 +95,7 @@ void IndexedHandleResource<THandle, TStruct, size, enumValue>::Free(
|
||||
int16_t index = getHandleTypedIndex(handle, enumValue, m_version);
|
||||
if (index < 0 || index >= size) return;
|
||||
// lock and deallocated handle
|
||||
std::lock_guard<std::mutex> sync(m_handleMutexes[index]);
|
||||
std::lock_guard<wpi::mutex> sync(m_handleMutexes[index]);
|
||||
m_structures[index].reset();
|
||||
}
|
||||
|
||||
@@ -102,7 +103,7 @@ template <typename THandle, typename TStruct, int16_t size,
|
||||
HAL_HandleEnum enumValue>
|
||||
void IndexedHandleResource<THandle, TStruct, size, enumValue>::ResetHandles() {
|
||||
for (int i = 0; i < size; i++) {
|
||||
std::lock_guard<std::mutex> sync(m_handleMutexes[i]);
|
||||
std::lock_guard<wpi::mutex> sync(m_handleMutexes[i]);
|
||||
m_structures[i].reset();
|
||||
}
|
||||
HandleBase::ResetHandles();
|
||||
|
||||
@@ -11,7 +11,8 @@
|
||||
|
||||
#include <array>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
#include <support/mutex.h>
|
||||
|
||||
#include "HAL/Types.h"
|
||||
#include "HAL/cpp/make_unique.h"
|
||||
@@ -48,8 +49,8 @@ class LimitedClassedHandleResource : public HandleBase {
|
||||
|
||||
private:
|
||||
std::array<std::shared_ptr<TStruct>, size> m_structures;
|
||||
std::array<std::mutex, size> m_handleMutexes;
|
||||
std::mutex m_allocateMutex;
|
||||
std::array<wpi::mutex, size> m_handleMutexes;
|
||||
wpi::mutex m_allocateMutex;
|
||||
};
|
||||
|
||||
template <typename THandle, typename TStruct, int16_t size,
|
||||
@@ -58,12 +59,12 @@ THandle
|
||||
LimitedClassedHandleResource<THandle, TStruct, size, enumValue>::Allocate(
|
||||
std::shared_ptr<TStruct> toSet) {
|
||||
// globally lock to loop through indices
|
||||
std::lock_guard<std::mutex> sync(m_allocateMutex);
|
||||
std::lock_guard<wpi::mutex> sync(m_allocateMutex);
|
||||
for (int16_t i = 0; i < size; i++) {
|
||||
if (m_structures[i] == nullptr) {
|
||||
// if a false index is found, grab its specific mutex
|
||||
// and allocate it.
|
||||
std::lock_guard<std::mutex> sync(m_handleMutexes[i]);
|
||||
std::lock_guard<wpi::mutex> sync(m_handleMutexes[i]);
|
||||
m_structures[i] = toSet;
|
||||
return static_cast<THandle>(createHandle(i, enumValue, m_version));
|
||||
}
|
||||
@@ -81,7 +82,7 @@ LimitedClassedHandleResource<THandle, TStruct, size, enumValue>::Get(
|
||||
if (index < 0 || index >= size) {
|
||||
return nullptr;
|
||||
}
|
||||
std::lock_guard<std::mutex> sync(m_handleMutexes[index]);
|
||||
std::lock_guard<wpi::mutex> sync(m_handleMutexes[index]);
|
||||
// return structure. Null will propogate correctly, so no need to manually
|
||||
// check.
|
||||
return m_structures[index];
|
||||
@@ -95,8 +96,8 @@ void LimitedClassedHandleResource<THandle, TStruct, size, enumValue>::Free(
|
||||
int16_t index = getHandleTypedIndex(handle, enumValue, m_version);
|
||||
if (index < 0 || index >= size) return;
|
||||
// lock and deallocated handle
|
||||
std::lock_guard<std::mutex> sync(m_allocateMutex);
|
||||
std::lock_guard<std::mutex> lock(m_handleMutexes[index]);
|
||||
std::lock_guard<wpi::mutex> sync(m_allocateMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_handleMutexes[index]);
|
||||
m_structures[index].reset();
|
||||
}
|
||||
|
||||
@@ -105,9 +106,9 @@ template <typename THandle, typename TStruct, int16_t size,
|
||||
void LimitedClassedHandleResource<THandle, TStruct, size,
|
||||
enumValue>::ResetHandles() {
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_allocateMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_allocateMutex);
|
||||
for (int i = 0; i < size; i++) {
|
||||
std::lock_guard<std::mutex> sync(m_handleMutexes[i]);
|
||||
std::lock_guard<wpi::mutex> sync(m_handleMutexes[i]);
|
||||
m_structures[i].reset();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,8 @@
|
||||
|
||||
#include <array>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
#include <support/mutex.h>
|
||||
|
||||
#include "HAL/Types.h"
|
||||
#include "HAL/cpp/make_unique.h"
|
||||
@@ -46,20 +47,20 @@ class LimitedHandleResource : public HandleBase {
|
||||
|
||||
private:
|
||||
std::array<std::shared_ptr<TStruct>, size> m_structures;
|
||||
std::array<std::mutex, size> m_handleMutexes;
|
||||
std::mutex m_allocateMutex;
|
||||
std::array<wpi::mutex, size> m_handleMutexes;
|
||||
wpi::mutex m_allocateMutex;
|
||||
};
|
||||
|
||||
template <typename THandle, typename TStruct, int16_t size,
|
||||
HAL_HandleEnum enumValue>
|
||||
THandle LimitedHandleResource<THandle, TStruct, size, enumValue>::Allocate() {
|
||||
// globally lock to loop through indices
|
||||
std::lock_guard<std::mutex> sync(m_allocateMutex);
|
||||
std::lock_guard<wpi::mutex> sync(m_allocateMutex);
|
||||
for (int16_t i = 0; i < size; i++) {
|
||||
if (m_structures[i] == nullptr) {
|
||||
// if a false index is found, grab its specific mutex
|
||||
// and allocate it.
|
||||
std::lock_guard<std::mutex> sync(m_handleMutexes[i]);
|
||||
std::lock_guard<wpi::mutex> sync(m_handleMutexes[i]);
|
||||
m_structures[i] = std::make_shared<TStruct>();
|
||||
return static_cast<THandle>(createHandle(i, enumValue, m_version));
|
||||
}
|
||||
@@ -76,7 +77,7 @@ LimitedHandleResource<THandle, TStruct, size, enumValue>::Get(THandle handle) {
|
||||
if (index < 0 || index >= size) {
|
||||
return nullptr;
|
||||
}
|
||||
std::lock_guard<std::mutex> sync(m_handleMutexes[index]);
|
||||
std::lock_guard<wpi::mutex> sync(m_handleMutexes[index]);
|
||||
// return structure. Null will propogate correctly, so no need to manually
|
||||
// check.
|
||||
return m_structures[index];
|
||||
@@ -90,8 +91,8 @@ void LimitedHandleResource<THandle, TStruct, size, enumValue>::Free(
|
||||
int16_t index = getHandleTypedIndex(handle, enumValue, m_version);
|
||||
if (index < 0 || index >= size) return;
|
||||
// lock and deallocated handle
|
||||
std::lock_guard<std::mutex> sync(m_allocateMutex);
|
||||
std::lock_guard<std::mutex> lock(m_handleMutexes[index]);
|
||||
std::lock_guard<wpi::mutex> sync(m_allocateMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_handleMutexes[index]);
|
||||
m_structures[index].reset();
|
||||
}
|
||||
|
||||
@@ -99,9 +100,9 @@ template <typename THandle, typename TStruct, int16_t size,
|
||||
HAL_HandleEnum enumValue>
|
||||
void LimitedHandleResource<THandle, TStruct, size, enumValue>::ResetHandles() {
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_allocateMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_allocateMutex);
|
||||
for (int i = 0; i < size; i++) {
|
||||
std::lock_guard<std::mutex> sync(m_handleMutexes[i]);
|
||||
std::lock_guard<wpi::mutex> sync(m_handleMutexes[i]);
|
||||
m_structures[i].reset();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,9 +10,10 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
|
||||
#include <support/mutex.h>
|
||||
|
||||
#include "HAL/Types.h"
|
||||
#include "HAL/handles/HandlesInternal.h"
|
||||
|
||||
@@ -48,13 +49,13 @@ class UnlimitedHandleResource : public HandleBase {
|
||||
|
||||
private:
|
||||
std::vector<std::shared_ptr<TStruct>> m_structures;
|
||||
std::mutex m_handleMutex;
|
||||
wpi::mutex m_handleMutex;
|
||||
};
|
||||
|
||||
template <typename THandle, typename TStruct, HAL_HandleEnum enumValue>
|
||||
THandle UnlimitedHandleResource<THandle, TStruct, enumValue>::Allocate(
|
||||
std::shared_ptr<TStruct> structure) {
|
||||
std::lock_guard<std::mutex> sync(m_handleMutex);
|
||||
std::lock_guard<wpi::mutex> sync(m_handleMutex);
|
||||
size_t i;
|
||||
for (i = 0; i < m_structures.size(); i++) {
|
||||
if (m_structures[i] == nullptr) {
|
||||
@@ -73,7 +74,7 @@ template <typename THandle, typename TStruct, HAL_HandleEnum enumValue>
|
||||
std::shared_ptr<TStruct>
|
||||
UnlimitedHandleResource<THandle, TStruct, enumValue>::Get(THandle handle) {
|
||||
int16_t index = getHandleTypedIndex(handle, enumValue, m_version);
|
||||
std::lock_guard<std::mutex> sync(m_handleMutex);
|
||||
std::lock_guard<wpi::mutex> sync(m_handleMutex);
|
||||
if (index < 0 || index >= static_cast<int16_t>(m_structures.size()))
|
||||
return nullptr;
|
||||
return m_structures[index];
|
||||
@@ -83,7 +84,7 @@ template <typename THandle, typename TStruct, HAL_HandleEnum enumValue>
|
||||
void UnlimitedHandleResource<THandle, TStruct, enumValue>::Free(
|
||||
THandle handle) {
|
||||
int16_t index = getHandleTypedIndex(handle, enumValue, m_version);
|
||||
std::lock_guard<std::mutex> sync(m_handleMutex);
|
||||
std::lock_guard<wpi::mutex> sync(m_handleMutex);
|
||||
if (index < 0 || index >= static_cast<int16_t>(m_structures.size())) return;
|
||||
m_structures[index].reset();
|
||||
}
|
||||
@@ -91,7 +92,7 @@ void UnlimitedHandleResource<THandle, TStruct, enumValue>::Free(
|
||||
template <typename THandle, typename TStruct, HAL_HandleEnum enumValue>
|
||||
void UnlimitedHandleResource<THandle, TStruct, enumValue>::ResetHandles() {
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_handleMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_handleMutex);
|
||||
for (size_t i = 0; i < m_structures.size(); i++) {
|
||||
m_structures[i].reset();
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <queue>
|
||||
#include <vector>
|
||||
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2017 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include "HAL/cpp/priority_mutex.h"
|
||||
|
||||
#if defined(__linux__)
|
||||
|
||||
using namespace hal;
|
||||
|
||||
void priority_recursive_mutex::lock() { pthread_mutex_lock(&m_mutex); }
|
||||
|
||||
void priority_recursive_mutex::unlock() { pthread_mutex_unlock(&m_mutex); }
|
||||
|
||||
bool priority_recursive_mutex::try_lock() noexcept {
|
||||
return !pthread_mutex_trylock(&m_mutex);
|
||||
}
|
||||
|
||||
pthread_mutex_t* priority_recursive_mutex::native_handle() { return &m_mutex; }
|
||||
|
||||
void priority_mutex::lock() { pthread_mutex_lock(&m_mutex); }
|
||||
|
||||
void priority_mutex::unlock() { pthread_mutex_unlock(&m_mutex); }
|
||||
|
||||
bool priority_mutex::try_lock() noexcept {
|
||||
return !pthread_mutex_trylock(&m_mutex);
|
||||
}
|
||||
|
||||
pthread_mutex_t* priority_mutex::native_handle() { return &m_mutex; }
|
||||
|
||||
#endif
|
||||
@@ -8,19 +8,19 @@
|
||||
#include "HAL/handles/HandlesInternal.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <mutex>
|
||||
|
||||
#include <llvm/SmallVector.h>
|
||||
#include <support/mutex.h>
|
||||
|
||||
namespace hal {
|
||||
static llvm::SmallVector<HandleBase*, 32> globalHandles;
|
||||
static std::mutex& GetGlobalHandleMutex() {
|
||||
static std::mutex globalHandleMutex;
|
||||
static wpi::mutex& GetGlobalHandleMutex() {
|
||||
static wpi::mutex globalHandleMutex;
|
||||
return globalHandleMutex;
|
||||
}
|
||||
|
||||
HandleBase::HandleBase() {
|
||||
std::lock_guard<std::mutex> lock(GetGlobalHandleMutex());
|
||||
std::lock_guard<wpi::mutex> lock(GetGlobalHandleMutex());
|
||||
auto index = std::find(globalHandles.begin(), globalHandles.end(), this);
|
||||
if (index == globalHandles.end()) {
|
||||
globalHandles.push_back(this);
|
||||
@@ -30,7 +30,7 @@ HandleBase::HandleBase() {
|
||||
}
|
||||
|
||||
HandleBase::~HandleBase() {
|
||||
std::lock_guard<std::mutex> lock(GetGlobalHandleMutex());
|
||||
std::lock_guard<wpi::mutex> lock(GetGlobalHandleMutex());
|
||||
auto index = std::find(globalHandles.begin(), globalHandles.end(), this);
|
||||
if (index != globalHandles.end()) {
|
||||
*index = nullptr;
|
||||
@@ -45,7 +45,7 @@ void HandleBase::ResetHandles() {
|
||||
}
|
||||
|
||||
void HandleBase::ResetGlobalHandles() {
|
||||
std::unique_lock<std::mutex> lock(GetGlobalHandleMutex());
|
||||
std::unique_lock<wpi::mutex> lock(GetGlobalHandleMutex());
|
||||
for (auto&& i : globalHandles) {
|
||||
if (i != nullptr) {
|
||||
lock.unlock();
|
||||
|
||||
@@ -11,19 +11,20 @@
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
|
||||
#include <condition_variable>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
|
||||
#include <support/condition_variable.h>
|
||||
#include <support/mutex.h>
|
||||
|
||||
#include "MockData/DriverStationDataInternal.h"
|
||||
#include "MockData/MockHooks.h"
|
||||
|
||||
static std::mutex msgMutex;
|
||||
static std::condition_variable newDSDataAvailableCond;
|
||||
static std::mutex newDSDataAvailableMutex;
|
||||
static wpi::mutex msgMutex;
|
||||
static wpi::condition_variable newDSDataAvailableCond;
|
||||
static wpi::mutex newDSDataAvailableMutex;
|
||||
static int newDSDataAvailableCounter{0};
|
||||
|
||||
using namespace hal;
|
||||
@@ -35,7 +36,7 @@ int32_t HAL_SendError(HAL_Bool isError, int32_t errorCode, HAL_Bool isLVCode,
|
||||
// Avoid flooding console by keeping track of previous 5 error
|
||||
// messages and only printing again if they're longer than 1 second old.
|
||||
static constexpr int KEEP_MSGS = 5;
|
||||
std::lock_guard<std::mutex> lock(msgMutex);
|
||||
std::lock_guard<wpi::mutex> lock(msgMutex);
|
||||
static std::string prevMsg[KEEP_MSGS];
|
||||
static std::chrono::time_point<std::chrono::steady_clock>
|
||||
prevMsgTime[KEEP_MSGS];
|
||||
@@ -220,7 +221,7 @@ bool HAL_IsNewControlData(void) {
|
||||
// worth the cycles to check.
|
||||
int currentCount = 0;
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(newDSDataAvailableMutex);
|
||||
std::unique_lock<wpi::mutex> lock(newDSDataAvailableMutex);
|
||||
currentCount = newDSDataAvailableCounter;
|
||||
}
|
||||
if (lastCount == currentCount) return false;
|
||||
@@ -242,7 +243,7 @@ HAL_Bool HAL_WaitForDSDataTimeout(double timeout) {
|
||||
auto timeoutTime =
|
||||
std::chrono::steady_clock::now() + std::chrono::duration<double>(timeout);
|
||||
|
||||
std::unique_lock<std::mutex> lock(newDSDataAvailableMutex);
|
||||
std::unique_lock<wpi::mutex> lock(newDSDataAvailableMutex);
|
||||
int currentCount = newDSDataAvailableCounter;
|
||||
while (newDSDataAvailableCounter == currentCount) {
|
||||
if (timeout > 0) {
|
||||
@@ -264,7 +265,7 @@ static int32_t newDataOccur(uint32_t refNum) {
|
||||
// Since we could get other values, require our specific handle
|
||||
// to signal our threads
|
||||
if (refNum != refNumber) return 0;
|
||||
std::lock_guard<std::mutex> lock(newDSDataAvailableMutex);
|
||||
std::lock_guard<wpi::mutex> lock(newDSDataAvailableMutex);
|
||||
// Nofify all threads
|
||||
newDSDataAvailableCounter++;
|
||||
newDSDataAvailableCond.notify_all();
|
||||
@@ -278,11 +279,11 @@ static int32_t newDataOccur(uint32_t refNum) {
|
||||
*/
|
||||
void HAL_InitializeDriverStation(void) {
|
||||
static std::atomic_bool initialized{false};
|
||||
static std::mutex initializeMutex;
|
||||
static wpi::mutex initializeMutex;
|
||||
// Initial check, as if it's true initialization has finished
|
||||
if (initialized) return;
|
||||
|
||||
std::lock_guard<std::mutex> lock(initializeMutex);
|
||||
std::lock_guard<wpi::mutex> lock(initializeMutex);
|
||||
// Second check in case another thread was waiting
|
||||
if (initialized) return;
|
||||
|
||||
|
||||
@@ -198,11 +198,11 @@ HAL_Bool HAL_GetBrownedOut(int32_t* status) {
|
||||
|
||||
HAL_Bool HAL_Initialize(int32_t timeout, int32_t mode) {
|
||||
static std::atomic_bool initialized{false};
|
||||
static std::mutex initializeMutex;
|
||||
static wpi::mutex initializeMutex;
|
||||
// Initial check, as if it's true initialization has finished
|
||||
if (initialized) return true;
|
||||
|
||||
std::lock_guard<std::mutex> lock(initializeMutex);
|
||||
std::lock_guard<wpi::mutex> lock(initializeMutex);
|
||||
// Second check in case another thread was waiting
|
||||
if (initialized) return true;
|
||||
|
||||
|
||||
@@ -7,9 +7,10 @@
|
||||
|
||||
#include "HAL/Interrupts.h"
|
||||
|
||||
#include <condition_variable>
|
||||
#include <memory>
|
||||
|
||||
#include <support/condition_variable.h>
|
||||
|
||||
#include "AnalogInternal.h"
|
||||
#include "DigitalInternal.h"
|
||||
#include "ErrorsInternal.h"
|
||||
@@ -53,7 +54,7 @@ struct Interrupt {
|
||||
|
||||
struct SynchronousWaitData {
|
||||
HAL_InterruptHandle interruptHandle;
|
||||
std::condition_variable waitCond;
|
||||
wpi::condition_variable waitCond;
|
||||
HAL_Bool waitPredicate;
|
||||
};
|
||||
} // namespace
|
||||
@@ -191,7 +192,7 @@ static int64_t WaitForInterruptDigital(HAL_InterruptHandle handle,
|
||||
|
||||
bool timedOut = false;
|
||||
|
||||
std::mutex waitMutex;
|
||||
wpi::mutex waitMutex;
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1900
|
||||
auto timeoutTime = std::chrono::steady_clock::now() +
|
||||
@@ -203,7 +204,7 @@ static int64_t WaitForInterruptDigital(HAL_InterruptHandle handle,
|
||||
#endif
|
||||
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(waitMutex);
|
||||
std::unique_lock<wpi::mutex> lock(waitMutex);
|
||||
while (!data->waitPredicate) {
|
||||
if (data->waitCond.wait_until(lock, timeoutTime) ==
|
||||
std::cv_status::timeout) {
|
||||
@@ -261,7 +262,7 @@ static int64_t WaitForInterruptAnalog(HAL_InterruptHandle handle,
|
||||
|
||||
bool timedOut = false;
|
||||
|
||||
std::mutex waitMutex;
|
||||
wpi::mutex waitMutex;
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1900
|
||||
auto timeoutTime = std::chrono::steady_clock::now() +
|
||||
@@ -273,7 +274,7 @@ static int64_t WaitForInterruptAnalog(HAL_InterruptHandle handle,
|
||||
#endif
|
||||
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(waitMutex);
|
||||
std::unique_lock<wpi::mutex> lock(waitMutex);
|
||||
while (!data->waitPredicate) {
|
||||
if (data->waitCond.wait_until(lock, timeoutTime) ==
|
||||
std::cv_status::timeout) {
|
||||
|
||||
@@ -32,7 +32,7 @@ int32_t AccelerometerData::RegisterActiveCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_activeCallbacks =
|
||||
RegisterCallback(m_activeCallbacks, "Active", callback, param, &newUid);
|
||||
}
|
||||
@@ -68,7 +68,7 @@ int32_t AccelerometerData::RegisterRangeCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_rangeCallbacks =
|
||||
RegisterCallback(m_rangeCallbacks, "Range", callback, param, &newUid);
|
||||
}
|
||||
@@ -104,7 +104,7 @@ int32_t AccelerometerData::RegisterXCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_xCallbacks =
|
||||
RegisterCallback(m_xCallbacks, "X", callback, param, &newUid);
|
||||
}
|
||||
@@ -140,7 +140,7 @@ int32_t AccelerometerData::RegisterYCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_yCallbacks =
|
||||
RegisterCallback(m_yCallbacks, "Y", callback, param, &newUid);
|
||||
}
|
||||
@@ -176,7 +176,7 @@ int32_t AccelerometerData::RegisterZCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_zCallbacks =
|
||||
RegisterCallback(m_zCallbacks, "Z", callback, param, &newUid);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
|
||||
#include <support/mutex.h>
|
||||
|
||||
#include "MockData/AccelerometerData.h"
|
||||
#include "MockData/NotifyListenerVector.h"
|
||||
|
||||
@@ -54,7 +56,7 @@ class AccelerometerData {
|
||||
virtual void ResetData();
|
||||
|
||||
private:
|
||||
std::mutex m_registerMutex;
|
||||
wpi::mutex m_registerMutex;
|
||||
std::atomic<HAL_Bool> m_active{false};
|
||||
std::shared_ptr<NotifyListenerVector> m_activeCallbacks = nullptr;
|
||||
std::atomic<HAL_AccelerometerRange> m_range{
|
||||
|
||||
@@ -28,7 +28,7 @@ int32_t AnalogGyroData::RegisterAngleCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_angleCallbacks =
|
||||
RegisterCallback(m_angleCallbacks, "Angle", callback, param, &newUid);
|
||||
}
|
||||
@@ -64,7 +64,7 @@ int32_t AnalogGyroData::RegisterRateCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_rateCallbacks =
|
||||
RegisterCallback(m_rateCallbacks, "Rate", callback, param, &newUid);
|
||||
}
|
||||
@@ -100,7 +100,7 @@ int32_t AnalogGyroData::RegisterInitializedCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_initializedCallbacks = RegisterCallback(
|
||||
m_initializedCallbacks, "Initialized", callback, param, &newUid);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
|
||||
#include <support/mutex.h>
|
||||
|
||||
#include "MockData/AnalogGyroData.h"
|
||||
#include "MockData/NotifyListenerVector.h"
|
||||
|
||||
@@ -40,7 +42,7 @@ class AnalogGyroData {
|
||||
virtual void ResetData();
|
||||
|
||||
private:
|
||||
std::mutex m_registerMutex;
|
||||
wpi::mutex m_registerMutex;
|
||||
std::atomic<double> m_angle{0.0};
|
||||
std::shared_ptr<NotifyListenerVector> m_angleCallbacks = nullptr;
|
||||
std::atomic<double> m_rate{0.0};
|
||||
|
||||
@@ -40,7 +40,7 @@ int32_t AnalogInData::RegisterInitializedCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_initializedCallbacks = RegisterCallback(
|
||||
m_initializedCallbacks, "Initialized", callback, param, &newUid);
|
||||
}
|
||||
@@ -76,7 +76,7 @@ int32_t AnalogInData::RegisterAverageBitsCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_averageBitsCallbacks = RegisterCallback(
|
||||
m_averageBitsCallbacks, "AverageBits", callback, param, &newUid);
|
||||
}
|
||||
@@ -111,7 +111,7 @@ int32_t AnalogInData::RegisterOversampleBitsCallback(
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_oversampleBitsCallbacks = RegisterCallback(
|
||||
m_oversampleBitsCallbacks, "OversampleBits", callback, param, &newUid);
|
||||
}
|
||||
@@ -147,7 +147,7 @@ int32_t AnalogInData::RegisterVoltageCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_voltageCallbacks = RegisterCallback(m_voltageCallbacks, "Voltage",
|
||||
callback, param, &newUid);
|
||||
}
|
||||
@@ -182,7 +182,7 @@ int32_t AnalogInData::RegisterAccumulatorInitializedCallback(
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_accumulatorInitializedCallbacks =
|
||||
RegisterCallback(m_accumulatorInitializedCallbacks,
|
||||
"AccumulatorInitialized", callback, param, &newUid);
|
||||
@@ -222,7 +222,7 @@ int32_t AnalogInData::RegisterAccumulatorValueCallback(
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_accumulatorValueCallbacks =
|
||||
RegisterCallback(m_accumulatorValueCallbacks, "AccumulatorValue",
|
||||
callback, param, &newUid);
|
||||
@@ -259,7 +259,7 @@ int32_t AnalogInData::RegisterAccumulatorCountCallback(
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_accumulatorCountCallbacks =
|
||||
RegisterCallback(m_accumulatorCountCallbacks, "AccumulatorCount",
|
||||
callback, param, &newUid);
|
||||
@@ -296,7 +296,7 @@ int32_t AnalogInData::RegisterAccumulatorCenterCallback(
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_accumulatorCenterCallbacks =
|
||||
RegisterCallback(m_accumulatorCenterCallbacks, "AccumulatorCenter",
|
||||
callback, param, &newUid);
|
||||
@@ -333,7 +333,7 @@ int32_t AnalogInData::RegisterAccumulatorDeadbandCallback(
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_accumulatorDeadbandCallbacks =
|
||||
RegisterCallback(m_accumulatorDeadbandCallbacks, "AccumulatorDeadband",
|
||||
callback, param, &newUid);
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
|
||||
#include <support/mutex.h>
|
||||
|
||||
#include "MockData/AnalogInData.h"
|
||||
#include "MockData/NotifyListenerVector.h"
|
||||
|
||||
@@ -85,7 +87,7 @@ class AnalogInData {
|
||||
virtual void ResetData();
|
||||
|
||||
private:
|
||||
std::mutex m_registerMutex;
|
||||
wpi::mutex m_registerMutex;
|
||||
std::atomic<HAL_Bool> m_initialized{false};
|
||||
std::shared_ptr<NotifyListenerVector> m_initializedCallbacks = nullptr;
|
||||
std::atomic<int32_t> m_averageBits{7};
|
||||
|
||||
@@ -26,7 +26,7 @@ int32_t AnalogOutData::RegisterVoltageCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_voltageCallbacks = RegisterCallback(m_voltageCallbacks, "Voltage",
|
||||
callback, param, &newUid);
|
||||
}
|
||||
@@ -62,7 +62,7 @@ int32_t AnalogOutData::RegisterInitializedCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_initializedCallbacks = RegisterCallback(
|
||||
m_initializedCallbacks, "Initialized", callback, param, &newUid);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
|
||||
#include <support/mutex.h>
|
||||
|
||||
#include "MockData/AnalogOutData.h"
|
||||
#include "MockData/NotifyListenerVector.h"
|
||||
|
||||
@@ -33,7 +35,7 @@ class AnalogOutData {
|
||||
virtual void ResetData();
|
||||
|
||||
private:
|
||||
std::mutex m_registerMutex;
|
||||
wpi::mutex m_registerMutex;
|
||||
std::atomic<double> m_voltage{0.0};
|
||||
std::shared_ptr<NotifyListenerVector> m_voltageCallbacks = nullptr;
|
||||
std::atomic<HAL_Bool> m_initialized{0};
|
||||
|
||||
@@ -29,7 +29,7 @@ int32_t AnalogTriggerData::RegisterInitializedCallback(
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_initializedCallbacks = RegisterCallback(
|
||||
m_initializedCallbacks, "Initialized", callback, param, &newUid);
|
||||
}
|
||||
@@ -64,7 +64,7 @@ int32_t AnalogTriggerData::RegisterTriggerLowerBoundCallback(
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_triggerLowerBoundCallbacks =
|
||||
RegisterCallback(m_triggerLowerBoundCallbacks, "TriggerLowerBound",
|
||||
callback, param, &newUid);
|
||||
@@ -101,7 +101,7 @@ int32_t AnalogTriggerData::RegisterTriggerUpperBoundCallback(
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_triggerUpperBoundCallbacks =
|
||||
RegisterCallback(m_triggerUpperBoundCallbacks, "TriggerUpperBound",
|
||||
callback, param, &newUid);
|
||||
@@ -138,7 +138,7 @@ int32_t AnalogTriggerData::RegisterTriggerModeCallback(
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_triggerModeCallbacks = RegisterCallback(
|
||||
m_triggerModeCallbacks, "TriggerMode", callback, param, &newUid);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
|
||||
#include <support/mutex.h>
|
||||
|
||||
#include "MockData/AnalogTriggerData.h"
|
||||
#include "MockData/NotifyListenerVector.h"
|
||||
|
||||
@@ -49,7 +51,7 @@ class AnalogTriggerData {
|
||||
virtual void ResetData();
|
||||
|
||||
private:
|
||||
std::mutex m_registerMutex;
|
||||
wpi::mutex m_registerMutex;
|
||||
std::atomic<HAL_Bool> m_initialized{0};
|
||||
std::shared_ptr<NotifyListenerVector> m_initializedCallbacks = nullptr;
|
||||
std::atomic<double> m_triggerLowerBound{0};
|
||||
|
||||
@@ -32,7 +32,7 @@ int32_t DIOData::RegisterInitializedCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_initializedCallbacks = RegisterCallback(
|
||||
m_initializedCallbacks, "Initialized", callback, param, &newUid);
|
||||
}
|
||||
@@ -67,7 +67,7 @@ int32_t DIOData::RegisterValueCallback(HAL_NotifyCallback callback, void* param,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_valueCallbacks =
|
||||
RegisterCallback(m_valueCallbacks, "Value", callback, param, &newUid);
|
||||
}
|
||||
@@ -103,7 +103,7 @@ int32_t DIOData::RegisterPulseLengthCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_pulseLengthCallbacks = RegisterCallback(
|
||||
m_pulseLengthCallbacks, "PulseLength", callback, param, &newUid);
|
||||
}
|
||||
@@ -138,7 +138,7 @@ int32_t DIOData::RegisterIsInputCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_isInputCallbacks = RegisterCallback(m_isInputCallbacks, "IsInput",
|
||||
callback, param, &newUid);
|
||||
}
|
||||
@@ -174,7 +174,7 @@ int32_t DIOData::RegisterFilterIndexCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_filterIndexCallbacks = RegisterCallback(
|
||||
m_filterIndexCallbacks, "FilterIndex", callback, param, &newUid);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
|
||||
#include <support/mutex.h>
|
||||
|
||||
#include "MockData/DIOData.h"
|
||||
#include "MockData/NotifyListenerVector.h"
|
||||
|
||||
@@ -54,7 +56,7 @@ class DIOData {
|
||||
virtual void ResetData();
|
||||
|
||||
private:
|
||||
std::mutex m_registerMutex;
|
||||
wpi::mutex m_registerMutex;
|
||||
std::atomic<HAL_Bool> m_initialized{false};
|
||||
std::shared_ptr<NotifyListenerVector> m_initializedCallbacks = nullptr;
|
||||
std::atomic<HAL_Bool> m_value{true};
|
||||
|
||||
@@ -28,7 +28,7 @@ int32_t DigitalPWMData::RegisterInitializedCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_initializedCallbacks = RegisterCallback(
|
||||
m_initializedCallbacks, "Initialized", callback, param, &newUid);
|
||||
}
|
||||
@@ -64,7 +64,7 @@ int32_t DigitalPWMData::RegisterDutyCycleCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_dutyCycleCallbacks = RegisterCallback(m_dutyCycleCallbacks, "DutyCycle",
|
||||
callback, param, &newUid);
|
||||
}
|
||||
@@ -100,7 +100,7 @@ int32_t DigitalPWMData::RegisterPinCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_pinCallbacks =
|
||||
RegisterCallback(m_pinCallbacks, "Pin", callback, param, &newUid);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
|
||||
#include <support/mutex.h>
|
||||
|
||||
#include "MockData/DigitalPWMData.h"
|
||||
#include "MockData/NotifyListenerVector.h"
|
||||
|
||||
@@ -40,7 +42,7 @@ class DigitalPWMData {
|
||||
virtual void ResetData();
|
||||
|
||||
private:
|
||||
std::mutex m_registerMutex;
|
||||
wpi::mutex m_registerMutex;
|
||||
std::atomic<HAL_Bool> m_initialized{false};
|
||||
std::shared_ptr<NotifyListenerVector> m_initializedCallbacks = nullptr;
|
||||
std::atomic<double> m_dutyCycle{false};
|
||||
|
||||
@@ -49,7 +49,7 @@ void DriverStationData::ResetData() {
|
||||
m_dsAttachedCallbacks = nullptr;
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_joystickDataMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_joystickDataMutex);
|
||||
m_joystickAxes = std::make_unique<HAL_JoystickAxes[]>(6);
|
||||
m_joystickPOVs = std::make_unique<HAL_JoystickPOVs[]>(6);
|
||||
m_joystickButtons = std::make_unique<HAL_JoystickButtons[]>(6);
|
||||
@@ -66,7 +66,7 @@ void DriverStationData::ResetData() {
|
||||
}
|
||||
}
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_matchInfoMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_matchInfoMutex);
|
||||
|
||||
m_matchInfo = std::make_unique<MatchInfoDataStore>();
|
||||
}
|
||||
@@ -79,7 +79,7 @@ int32_t DriverStationData::RegisterEnabledCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_enabledCallbacks = RegisterCallback(m_enabledCallbacks, "Enabled",
|
||||
callback, param, &newUid);
|
||||
}
|
||||
@@ -114,7 +114,7 @@ int32_t DriverStationData::RegisterAutonomousCallback(
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_autonomousCallbacks = RegisterCallback(
|
||||
m_autonomousCallbacks, "Autonomous", callback, param, &newUid);
|
||||
}
|
||||
@@ -150,7 +150,7 @@ int32_t DriverStationData::RegisterTestCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_testCallbacks =
|
||||
RegisterCallback(m_testCallbacks, "Test", callback, param, &newUid);
|
||||
}
|
||||
@@ -186,7 +186,7 @@ int32_t DriverStationData::RegisterEStopCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_eStopCallbacks =
|
||||
RegisterCallback(m_eStopCallbacks, "EStop", callback, param, &newUid);
|
||||
}
|
||||
@@ -221,7 +221,7 @@ int32_t DriverStationData::RegisterFmsAttachedCallback(
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_fmsAttachedCallbacks = RegisterCallback(
|
||||
m_fmsAttachedCallbacks, "FmsAttached", callback, param, &newUid);
|
||||
}
|
||||
@@ -256,7 +256,7 @@ int32_t DriverStationData::RegisterDsAttachedCallback(
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_dsAttachedCallbacks = RegisterCallback(
|
||||
m_dsAttachedCallbacks, "DsAttached", callback, param, &newUid);
|
||||
}
|
||||
@@ -291,7 +291,7 @@ int32_t DriverStationData::RegisterAllianceStationIdCallback(
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_allianceStationIdCallbacks =
|
||||
RegisterCallback(m_allianceStationIdCallbacks, "AllianceStationId",
|
||||
callback, param, &newUid);
|
||||
@@ -332,7 +332,7 @@ int32_t DriverStationData::RegisterMatchTimeCallback(
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_matchTimeCallbacks = RegisterCallback(m_matchTimeCallbacks, "MatchTime",
|
||||
callback, param, &newUid);
|
||||
}
|
||||
@@ -363,22 +363,22 @@ void DriverStationData::SetMatchTime(double matchTime) {
|
||||
|
||||
void DriverStationData::GetJoystickAxes(int32_t joystickNum,
|
||||
HAL_JoystickAxes* axes) {
|
||||
std::lock_guard<std::mutex> lock(m_joystickDataMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_joystickDataMutex);
|
||||
*axes = m_joystickAxes[joystickNum];
|
||||
}
|
||||
void DriverStationData::GetJoystickPOVs(int32_t joystickNum,
|
||||
HAL_JoystickPOVs* povs) {
|
||||
std::lock_guard<std::mutex> lock(m_joystickDataMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_joystickDataMutex);
|
||||
*povs = m_joystickPOVs[joystickNum];
|
||||
}
|
||||
void DriverStationData::GetJoystickButtons(int32_t joystickNum,
|
||||
HAL_JoystickButtons* buttons) {
|
||||
std::lock_guard<std::mutex> lock(m_joystickDataMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_joystickDataMutex);
|
||||
*buttons = m_joystickButtons[joystickNum];
|
||||
}
|
||||
void DriverStationData::GetJoystickDescriptor(
|
||||
int32_t joystickNum, HAL_JoystickDescriptor* descriptor) {
|
||||
std::lock_guard<std::mutex> lock(m_joystickDataMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_joystickDataMutex);
|
||||
*descriptor = m_joystickDescriptor[joystickNum];
|
||||
// Always ensure name is null terminated
|
||||
descriptor->name[255] = '\0';
|
||||
@@ -387,13 +387,13 @@ void DriverStationData::GetJoystickOutputs(int32_t joystickNum,
|
||||
int64_t* outputs,
|
||||
int32_t* leftRumble,
|
||||
int32_t* rightRumble) {
|
||||
std::lock_guard<std::mutex> lock(m_joystickDataMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_joystickDataMutex);
|
||||
*leftRumble = m_joystickOutputs[joystickNum].leftRumble;
|
||||
*outputs = m_joystickOutputs[joystickNum].outputs;
|
||||
*rightRumble = m_joystickOutputs[joystickNum].rightRumble;
|
||||
}
|
||||
void DriverStationData::GetMatchInfo(HAL_MatchInfo* info) {
|
||||
std::lock_guard<std::mutex> lock(m_matchInfoMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_matchInfoMutex);
|
||||
auto eventLen = m_matchInfo->eventName.size();
|
||||
info->eventName = static_cast<char*>(std::malloc(eventLen + 1));
|
||||
std::memcpy(info->eventName, m_matchInfo->eventName.c_str(), eventLen);
|
||||
@@ -414,37 +414,37 @@ void DriverStationData::FreeMatchInfo(const HAL_MatchInfo* info) {
|
||||
|
||||
void DriverStationData::SetJoystickAxes(int32_t joystickNum,
|
||||
const HAL_JoystickAxes* axes) {
|
||||
std::lock_guard<std::mutex> lock(m_joystickDataMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_joystickDataMutex);
|
||||
m_joystickAxes[joystickNum] = *axes;
|
||||
}
|
||||
void DriverStationData::SetJoystickPOVs(int32_t joystickNum,
|
||||
const HAL_JoystickPOVs* povs) {
|
||||
std::lock_guard<std::mutex> lock(m_joystickDataMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_joystickDataMutex);
|
||||
m_joystickPOVs[joystickNum] = *povs;
|
||||
}
|
||||
void DriverStationData::SetJoystickButtons(int32_t joystickNum,
|
||||
const HAL_JoystickButtons* buttons) {
|
||||
std::lock_guard<std::mutex> lock(m_joystickDataMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_joystickDataMutex);
|
||||
m_joystickButtons[joystickNum] = *buttons;
|
||||
}
|
||||
|
||||
void DriverStationData::SetJoystickDescriptor(
|
||||
int32_t joystickNum, const HAL_JoystickDescriptor* descriptor) {
|
||||
std::lock_guard<std::mutex> lock(m_joystickDataMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_joystickDataMutex);
|
||||
m_joystickDescriptor[joystickNum] = *descriptor;
|
||||
}
|
||||
|
||||
void DriverStationData::SetJoystickOutputs(int32_t joystickNum, int64_t outputs,
|
||||
int32_t leftRumble,
|
||||
int32_t rightRumble) {
|
||||
std::lock_guard<std::mutex> lock(m_joystickDataMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_joystickDataMutex);
|
||||
m_joystickOutputs[joystickNum].leftRumble = leftRumble;
|
||||
m_joystickOutputs[joystickNum].outputs = outputs;
|
||||
m_joystickOutputs[joystickNum].rightRumble = rightRumble;
|
||||
}
|
||||
|
||||
void DriverStationData::SetMatchInfo(const HAL_MatchInfo* info) {
|
||||
std::lock_guard<std::mutex> lock(m_matchInfoMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_matchInfoMutex);
|
||||
m_matchInfo->eventName = info->eventName;
|
||||
m_matchInfo->gameSpecificMessage = info->gameSpecificMessage;
|
||||
m_matchInfo->matchNumber = info->matchNumber;
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
|
||||
#include <support/mutex.h>
|
||||
|
||||
#include "MockData/DriverStationData.h"
|
||||
#include "MockData/NotifyListenerVector.h"
|
||||
|
||||
@@ -103,7 +105,7 @@ class DriverStationData {
|
||||
void NotifyNewData();
|
||||
|
||||
private:
|
||||
std::mutex m_registerMutex;
|
||||
wpi::mutex m_registerMutex;
|
||||
std::atomic<HAL_Bool> m_enabled{false};
|
||||
std::shared_ptr<NotifyListenerVector> m_enabledCallbacks = nullptr;
|
||||
std::atomic<HAL_Bool> m_autonomous{false};
|
||||
@@ -122,8 +124,8 @@ class DriverStationData {
|
||||
std::atomic<double> m_matchTime{0.0};
|
||||
std::shared_ptr<NotifyListenerVector> m_matchTimeCallbacks = nullptr;
|
||||
|
||||
std::mutex m_joystickDataMutex;
|
||||
std::mutex m_matchInfoMutex;
|
||||
wpi::mutex m_joystickDataMutex;
|
||||
wpi::mutex m_matchInfoMutex;
|
||||
|
||||
std::unique_ptr<HAL_JoystickAxes[]> m_joystickAxes;
|
||||
std::unique_ptr<HAL_JoystickPOVs[]> m_joystickPOVs;
|
||||
|
||||
@@ -38,7 +38,7 @@ int32_t EncoderData::RegisterInitializedCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_initializedCallbacks = RegisterCallback(
|
||||
m_initializedCallbacks, "Initialized", callback, param, &newUid);
|
||||
}
|
||||
@@ -74,7 +74,7 @@ int32_t EncoderData::RegisterCountCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_countCallbacks =
|
||||
RegisterCallback(m_countCallbacks, "Count", callback, param, &newUid);
|
||||
}
|
||||
@@ -110,7 +110,7 @@ int32_t EncoderData::RegisterPeriodCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_periodCallbacks =
|
||||
RegisterCallback(m_periodCallbacks, "Period", callback, param, &newUid);
|
||||
}
|
||||
@@ -146,7 +146,7 @@ int32_t EncoderData::RegisterResetCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_resetCallbacks =
|
||||
RegisterCallback(m_resetCallbacks, "Reset", callback, param, &newUid);
|
||||
}
|
||||
@@ -182,7 +182,7 @@ int32_t EncoderData::RegisterMaxPeriodCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_maxPeriodCallbacks = RegisterCallback(m_maxPeriodCallbacks, "MaxPeriod",
|
||||
callback, param, &newUid);
|
||||
}
|
||||
@@ -218,7 +218,7 @@ int32_t EncoderData::RegisterDirectionCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_directionCallbacks = RegisterCallback(m_directionCallbacks, "Direction",
|
||||
callback, param, &newUid);
|
||||
}
|
||||
@@ -253,7 +253,7 @@ int32_t EncoderData::RegisterReverseDirectionCallback(
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_reverseDirectionCallbacks =
|
||||
RegisterCallback(m_reverseDirectionCallbacks, "ReverseDirection",
|
||||
callback, param, &newUid);
|
||||
@@ -290,7 +290,7 @@ int32_t EncoderData::RegisterSamplesToAverageCallback(
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_samplesToAverageCallbacks =
|
||||
RegisterCallback(m_samplesToAverageCallbacks, "SamplesToAverage",
|
||||
callback, param, &newUid);
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
|
||||
#include <support/mutex.h>
|
||||
|
||||
#include "MockData/EncoderData.h"
|
||||
#include "MockData/NotifyListenerVector.h"
|
||||
|
||||
@@ -76,7 +78,7 @@ class EncoderData {
|
||||
virtual void ResetData();
|
||||
|
||||
private:
|
||||
std::mutex m_registerMutex;
|
||||
wpi::mutex m_registerMutex;
|
||||
std::atomic<HAL_Bool> m_initialized{false};
|
||||
std::shared_ptr<NotifyListenerVector> m_initializedCallbacks = nullptr;
|
||||
std::atomic<int32_t> m_count{0};
|
||||
|
||||
@@ -34,7 +34,7 @@ int32_t I2CData::RegisterInitializedCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_initializedCallbacks = RegisterCallback(
|
||||
m_initializedCallbacks, "Initialized", callback, param, &newUid);
|
||||
}
|
||||
@@ -69,7 +69,7 @@ int32_t I2CData::RegisterReadCallback(HAL_BufferCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_readCallbacks =
|
||||
RegisterCallback(m_readCallbacks, "Read", callback, param, &newUid);
|
||||
}
|
||||
@@ -86,7 +86,7 @@ int32_t I2CData::RegisterWriteCallback(HAL_BufferCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_writeCallbacks =
|
||||
RegisterCallback(m_writeCallbacks, "Write", callback, param, &newUid);
|
||||
}
|
||||
@@ -99,11 +99,11 @@ void I2CData::CancelWriteCallback(int32_t uid) {
|
||||
|
||||
void I2CData::Write(int32_t deviceAddress, uint8_t* dataToSend,
|
||||
int32_t sendSize) {
|
||||
std::lock_guard<std::mutex> lock(m_dataMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_dataMutex);
|
||||
InvokeCallback(m_writeCallbacks, "Write", dataToSend, sendSize);
|
||||
}
|
||||
void I2CData::Read(int32_t deviceAddress, uint8_t* buffer, int32_t count) {
|
||||
std::lock_guard<std::mutex> lock(m_dataMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_dataMutex);
|
||||
InvokeCallback(m_readCallbacks, "Read", buffer, count);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
|
||||
#include <support/mutex.h>
|
||||
|
||||
#include "MockData/I2CData.h"
|
||||
#include "MockData/NotifyListenerVector.h"
|
||||
|
||||
@@ -39,8 +41,8 @@ class I2CData {
|
||||
void ResetData();
|
||||
|
||||
private:
|
||||
std::mutex m_registerMutex;
|
||||
std::mutex m_dataMutex;
|
||||
wpi::mutex m_registerMutex;
|
||||
wpi::mutex m_dataMutex;
|
||||
std::atomic<HAL_Bool> m_initialized{false};
|
||||
std::shared_ptr<NotifyListenerVector> m_initializedCallbacks = nullptr;
|
||||
std::shared_ptr<BufferListenerVector> m_readCallbacks = nullptr;
|
||||
|
||||
@@ -38,7 +38,7 @@ int32_t PCMData::RegisterSolenoidInitializedCallback(
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_solenoidInitializedCallbacks[channel] =
|
||||
RegisterCallback(m_solenoidInitializedCallbacks[channel],
|
||||
"SolenoidInitialized", callback, param, &newUid);
|
||||
@@ -84,7 +84,7 @@ int32_t PCMData::RegisterSolenoidOutputCallback(int32_t channel,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_solenoidOutputCallbacks[channel] =
|
||||
RegisterCallback(m_solenoidOutputCallbacks[channel], "SolenoidOutput",
|
||||
callback, param, &newUid);
|
||||
@@ -123,7 +123,7 @@ int32_t PCMData::RegisterCompressorInitializedCallback(
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_compressorInitializedCallbacks =
|
||||
RegisterCallback(m_compressorInitializedCallbacks,
|
||||
"CompressorInitialized", callback, param, &newUid);
|
||||
@@ -162,7 +162,7 @@ int32_t PCMData::RegisterCompressorOnCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_compressorOnCallbacks = RegisterCallback(
|
||||
m_compressorOnCallbacks, "CompressorOn", callback, param, &newUid);
|
||||
}
|
||||
@@ -198,7 +198,7 @@ int32_t PCMData::RegisterClosedLoopEnabledCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_closedLoopEnabledCallbacks =
|
||||
RegisterCallback(m_closedLoopEnabledCallbacks, "ClosedLoopEnabled",
|
||||
callback, param, &newUid);
|
||||
@@ -236,7 +236,7 @@ int32_t PCMData::RegisterPressureSwitchCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_pressureSwitchCallbacks = RegisterCallback(
|
||||
m_pressureSwitchCallbacks, "PressureSwitch", callback, param, &newUid);
|
||||
}
|
||||
@@ -272,7 +272,7 @@ int32_t PCMData::RegisterCompressorCurrentCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_compressorCurrentCallbacks =
|
||||
RegisterCallback(m_compressorCurrentCallbacks, "CompressorCurrent",
|
||||
callback, param, &newUid);
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
|
||||
#include <support/mutex.h>
|
||||
|
||||
#include "../PortsInternal.h"
|
||||
#include "MockData/NotifyListenerVector.h"
|
||||
#include "MockData/PCMData.h"
|
||||
@@ -75,7 +77,7 @@ class PCMData {
|
||||
virtual void ResetData();
|
||||
|
||||
private:
|
||||
std::mutex m_registerMutex;
|
||||
wpi::mutex m_registerMutex;
|
||||
std::atomic<HAL_Bool> m_solenoidInitialized[kNumSolenoidChannels];
|
||||
std::shared_ptr<NotifyListenerVector>
|
||||
m_solenoidInitializedCallbacks[kNumSolenoidChannels];
|
||||
|
||||
@@ -32,7 +32,7 @@ int32_t PDPData::RegisterInitializedCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_initializedCallbacks = RegisterCallback(
|
||||
m_initializedCallbacks, "Initialized", callback, param, &newUid);
|
||||
}
|
||||
@@ -68,7 +68,7 @@ int32_t PDPData::RegisterTemperatureCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_temperatureCallbacks = RegisterCallback(
|
||||
m_temperatureCallbacks, "Temperature", callback, param, &newUid);
|
||||
}
|
||||
@@ -103,7 +103,7 @@ int32_t PDPData::RegisterVoltageCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_voltageCallbacks = RegisterCallback(m_voltageCallbacks, "Voltage",
|
||||
callback, param, &newUid);
|
||||
}
|
||||
@@ -139,7 +139,7 @@ int32_t PDPData::RegisterCurrentCallback(int32_t channel,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_currentCallbacks[channel] = RegisterCallback(
|
||||
m_currentCallbacks[channel], "Current", callback, param, &newUid);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
|
||||
#include <support/mutex.h>
|
||||
|
||||
#include "../PortsInternal.h"
|
||||
#include "MockData/NotifyListenerVector.h"
|
||||
#include "MockData/PDPData.h"
|
||||
@@ -48,7 +50,7 @@ class PDPData {
|
||||
virtual void ResetData();
|
||||
|
||||
private:
|
||||
std::mutex m_registerMutex;
|
||||
wpi::mutex m_registerMutex;
|
||||
std::atomic<HAL_Bool> m_initialized{false};
|
||||
std::shared_ptr<NotifyListenerVector> m_initializedCallbacks = nullptr;
|
||||
std::atomic<double> m_temperature{0.0};
|
||||
|
||||
@@ -34,7 +34,7 @@ int32_t PWMData::RegisterInitializedCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_initializedCallbacks = RegisterCallback(
|
||||
m_initializedCallbacks, "Initialized", callback, param, &newUid);
|
||||
}
|
||||
@@ -69,7 +69,7 @@ int32_t PWMData::RegisterRawValueCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_rawValueCallbacks = RegisterCallback(m_rawValueCallbacks, "RawValue",
|
||||
callback, param, &newUid);
|
||||
}
|
||||
@@ -104,7 +104,7 @@ int32_t PWMData::RegisterSpeedCallback(HAL_NotifyCallback callback, void* param,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_speedCallbacks =
|
||||
RegisterCallback(m_speedCallbacks, "Speed", callback, param, &newUid);
|
||||
}
|
||||
@@ -139,7 +139,7 @@ int32_t PWMData::RegisterPositionCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_positionCallbacks = RegisterCallback(m_positionCallbacks, "Position",
|
||||
callback, param, &newUid);
|
||||
}
|
||||
@@ -175,7 +175,7 @@ int32_t PWMData::RegisterPeriodScaleCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_periodScaleCallbacks = RegisterCallback(
|
||||
m_periodScaleCallbacks, "PeriodScale", callback, param, &newUid);
|
||||
}
|
||||
@@ -211,7 +211,7 @@ int32_t PWMData::RegisterZeroLatchCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_zeroLatchCallbacks = RegisterCallback(m_zeroLatchCallbacks, "ZeroLatch",
|
||||
callback, param, &newUid);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
|
||||
#include <support/mutex.h>
|
||||
|
||||
#include "MockData/NotifyListenerVector.h"
|
||||
#include "MockData/PWMData.h"
|
||||
|
||||
@@ -61,7 +63,7 @@ class PWMData {
|
||||
virtual void ResetData();
|
||||
|
||||
private:
|
||||
std::mutex m_registerMutex;
|
||||
wpi::mutex m_registerMutex;
|
||||
std::atomic<HAL_Bool> m_initialized{false};
|
||||
std::shared_ptr<NotifyListenerVector> m_initializedCallbacks = nullptr;
|
||||
std::atomic<int32_t> m_rawValue{0};
|
||||
|
||||
@@ -29,7 +29,7 @@ int32_t RelayData::RegisterInitializedForwardCallback(
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_initializedForwardCallbacks =
|
||||
RegisterCallback(m_initializedForwardCallbacks, "InitializedForward",
|
||||
callback, param, &newUid);
|
||||
@@ -66,7 +66,7 @@ int32_t RelayData::RegisterInitializedReverseCallback(
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_initializedReverseCallbacks =
|
||||
RegisterCallback(m_initializedReverseCallbacks, "InitializedReverse",
|
||||
callback, param, &newUid);
|
||||
@@ -104,7 +104,7 @@ int32_t RelayData::RegisterForwardCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_forwardCallbacks = RegisterCallback(m_forwardCallbacks, "Forward",
|
||||
callback, param, &newUid);
|
||||
}
|
||||
@@ -140,7 +140,7 @@ int32_t RelayData::RegisterReverseCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_reverseCallbacks = RegisterCallback(m_reverseCallbacks, "Reverse",
|
||||
callback, param, &newUid);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
|
||||
#include <support/mutex.h>
|
||||
|
||||
#include "MockData/NotifyListenerVector.h"
|
||||
#include "MockData/RelayData.h"
|
||||
|
||||
@@ -49,7 +51,7 @@ class RelayData {
|
||||
virtual void ResetData();
|
||||
|
||||
private:
|
||||
std::mutex m_registerMutex;
|
||||
wpi::mutex m_registerMutex;
|
||||
std::atomic<HAL_Bool> m_initializedForward{false};
|
||||
std::shared_ptr<NotifyListenerVector> m_initializedForwardCallbacks = nullptr;
|
||||
std::atomic<HAL_Bool> m_initializedReverse{false};
|
||||
|
||||
@@ -52,7 +52,7 @@ int32_t RoboRioData::RegisterFPGAButtonCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_fPGAButtonCallbacks = RegisterCallback(
|
||||
m_fPGAButtonCallbacks, "FPGAButton", callback, param, &newUid);
|
||||
}
|
||||
@@ -88,7 +88,7 @@ int32_t RoboRioData::RegisterVInVoltageCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_vInVoltageCallbacks = RegisterCallback(
|
||||
m_vInVoltageCallbacks, "VInVoltage", callback, param, &newUid);
|
||||
}
|
||||
@@ -124,7 +124,7 @@ int32_t RoboRioData::RegisterVInCurrentCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_vInCurrentCallbacks = RegisterCallback(
|
||||
m_vInCurrentCallbacks, "VInCurrent", callback, param, &newUid);
|
||||
}
|
||||
@@ -160,7 +160,7 @@ int32_t RoboRioData::RegisterUserVoltage6VCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_userVoltage6VCallbacks = RegisterCallback(
|
||||
m_userVoltage6VCallbacks, "UserVoltage6V", callback, param, &newUid);
|
||||
}
|
||||
@@ -196,7 +196,7 @@ int32_t RoboRioData::RegisterUserCurrent6VCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_userCurrent6VCallbacks = RegisterCallback(
|
||||
m_userCurrent6VCallbacks, "UserCurrent6V", callback, param, &newUid);
|
||||
}
|
||||
@@ -232,7 +232,7 @@ int32_t RoboRioData::RegisterUserActive6VCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_userActive6VCallbacks = RegisterCallback(
|
||||
m_userActive6VCallbacks, "UserActive6V", callback, param, &newUid);
|
||||
}
|
||||
@@ -268,7 +268,7 @@ int32_t RoboRioData::RegisterUserVoltage5VCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_userVoltage5VCallbacks = RegisterCallback(
|
||||
m_userVoltage5VCallbacks, "UserVoltage5V", callback, param, &newUid);
|
||||
}
|
||||
@@ -304,7 +304,7 @@ int32_t RoboRioData::RegisterUserCurrent5VCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_userCurrent5VCallbacks = RegisterCallback(
|
||||
m_userCurrent5VCallbacks, "UserCurrent5V", callback, param, &newUid);
|
||||
}
|
||||
@@ -340,7 +340,7 @@ int32_t RoboRioData::RegisterUserActive5VCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_userActive5VCallbacks = RegisterCallback(
|
||||
m_userActive5VCallbacks, "UserActive5V", callback, param, &newUid);
|
||||
}
|
||||
@@ -376,7 +376,7 @@ int32_t RoboRioData::RegisterUserVoltage3V3Callback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_userVoltage3V3Callbacks = RegisterCallback(
|
||||
m_userVoltage3V3Callbacks, "UserVoltage3V3", callback, param, &newUid);
|
||||
}
|
||||
@@ -412,7 +412,7 @@ int32_t RoboRioData::RegisterUserCurrent3V3Callback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_userCurrent3V3Callbacks = RegisterCallback(
|
||||
m_userCurrent3V3Callbacks, "UserCurrent3V3", callback, param, &newUid);
|
||||
}
|
||||
@@ -448,7 +448,7 @@ int32_t RoboRioData::RegisterUserActive3V3Callback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_userActive3V3Callbacks = RegisterCallback(
|
||||
m_userActive3V3Callbacks, "UserActive3V3", callback, param, &newUid);
|
||||
}
|
||||
@@ -484,7 +484,7 @@ int32_t RoboRioData::RegisterUserFaults6VCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_userFaults6VCallbacks = RegisterCallback(
|
||||
m_userFaults6VCallbacks, "UserFaults6V", callback, param, &newUid);
|
||||
}
|
||||
@@ -520,7 +520,7 @@ int32_t RoboRioData::RegisterUserFaults5VCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_userFaults5VCallbacks = RegisterCallback(
|
||||
m_userFaults5VCallbacks, "UserFaults5V", callback, param, &newUid);
|
||||
}
|
||||
@@ -556,7 +556,7 @@ int32_t RoboRioData::RegisterUserFaults3V3Callback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_userFaults3V3Callbacks = RegisterCallback(
|
||||
m_userFaults3V3Callbacks, "UserFaults3V3", callback, param, &newUid);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
|
||||
#include <support/mutex.h>
|
||||
|
||||
#include "MockData/NotifyListenerVector.h"
|
||||
#include "MockData/RoboRioData.h"
|
||||
|
||||
@@ -124,7 +126,7 @@ class RoboRioData {
|
||||
virtual void ResetData();
|
||||
|
||||
private:
|
||||
std::mutex m_registerMutex;
|
||||
wpi::mutex m_registerMutex;
|
||||
std::atomic<HAL_Bool> m_fPGAButton{false};
|
||||
std::shared_ptr<NotifyListenerVector> m_fPGAButtonCallbacks = nullptr;
|
||||
std::atomic<double> m_vInVoltage{0.0};
|
||||
|
||||
@@ -31,7 +31,7 @@ int32_t SPIAccelerometerData::RegisterActiveCallback(
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_activeCallbacks =
|
||||
RegisterCallback(m_activeCallbacks, "Active", callback, param, &newUid);
|
||||
}
|
||||
@@ -67,7 +67,7 @@ int32_t SPIAccelerometerData::RegisterRangeCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_rangeCallbacks =
|
||||
RegisterCallback(m_rangeCallbacks, "Range", callback, param, &newUid);
|
||||
}
|
||||
@@ -103,7 +103,7 @@ int32_t SPIAccelerometerData::RegisterXCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_xCallbacks =
|
||||
RegisterCallback(m_xCallbacks, "X", callback, param, &newUid);
|
||||
}
|
||||
@@ -139,7 +139,7 @@ int32_t SPIAccelerometerData::RegisterYCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_yCallbacks =
|
||||
RegisterCallback(m_yCallbacks, "Y", callback, param, &newUid);
|
||||
}
|
||||
@@ -175,7 +175,7 @@ int32_t SPIAccelerometerData::RegisterZCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_zCallbacks =
|
||||
RegisterCallback(m_zCallbacks, "Z", callback, param, &newUid);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
|
||||
#include <support/mutex.h>
|
||||
|
||||
#include "MockData/NotifyListenerVector.h"
|
||||
#include "MockData/SPIAccelerometerData.h"
|
||||
|
||||
@@ -54,7 +56,7 @@ class SPIAccelerometerData {
|
||||
virtual void ResetData();
|
||||
|
||||
private:
|
||||
std::mutex m_registerMutex;
|
||||
wpi::mutex m_registerMutex;
|
||||
std::atomic<HAL_Bool> m_active{false};
|
||||
std::shared_ptr<NotifyListenerVector> m_activeCallbacks = nullptr;
|
||||
std::atomic<int32_t> m_range{0};
|
||||
|
||||
@@ -35,7 +35,7 @@ int32_t SPIData::RegisterInitializedCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_initializedCallbacks = RegisterCallback(
|
||||
m_initializedCallbacks, "Initialized", callback, param, &newUid);
|
||||
}
|
||||
@@ -70,7 +70,7 @@ int32_t SPIData::RegisterReadCallback(HAL_BufferCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_readCallbacks =
|
||||
RegisterCallback(m_readCallbacks, "Read", callback, param, &newUid);
|
||||
}
|
||||
@@ -88,7 +88,7 @@ int32_t SPIData::RegisterWriteCallback(HAL_BufferCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_writeCallbacks =
|
||||
RegisterCallback(m_writeCallbacks, "Write", callback, param, &newUid);
|
||||
}
|
||||
@@ -107,7 +107,7 @@ int32_t SPIData::RegisterResetAccumulatorCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_resetAccumulatorCallback =
|
||||
RegisterCallback(m_resetAccumulatorCallback, "ResetAccumulator",
|
||||
callback, param, &newUid);
|
||||
@@ -131,7 +131,7 @@ int32_t SPIData::RegisterAccumulatorCallback(HAL_NotifyCallback callback,
|
||||
if (callback == nullptr) return -1;
|
||||
int32_t newUid = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_registerMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_registerMutex);
|
||||
m_setAccumulatorCallback = RegisterCallback(
|
||||
m_setAccumulatorCallback, "SetAccumulator", callback, param, &newUid);
|
||||
}
|
||||
@@ -161,14 +161,14 @@ void SPIData::SetAccumulatorValue(int64_t value) {
|
||||
int64_t SPIData::GetAccumulatorValue() { return m_accumulatorValue; }
|
||||
|
||||
int32_t SPIData::Read(uint8_t* buffer, int32_t count) {
|
||||
std::lock_guard<std::mutex> lock(m_dataMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_dataMutex);
|
||||
InvokeCallback(m_readCallbacks, "Read", buffer, count);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
int32_t SPIData::Write(uint8_t* dataToSend, int32_t sendSize) {
|
||||
std::lock_guard<std::mutex> lock(m_dataMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_dataMutex);
|
||||
InvokeCallback(m_writeCallbacks, "Write", dataToSend, sendSize);
|
||||
|
||||
return sendSize;
|
||||
@@ -176,7 +176,7 @@ int32_t SPIData::Write(uint8_t* dataToSend, int32_t sendSize) {
|
||||
|
||||
int32_t SPIData::Transaction(uint8_t* dataToSend, uint8_t* dataReceived,
|
||||
int32_t size) {
|
||||
std::lock_guard<std::mutex> lock(m_dataMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_dataMutex);
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
|
||||
#include <support/mutex.h>
|
||||
|
||||
#include "MockData/NotifyListenerVector.h"
|
||||
#include "MockData/SPIData.h"
|
||||
|
||||
@@ -52,8 +54,8 @@ class SPIData {
|
||||
void ResetData();
|
||||
|
||||
private:
|
||||
std::mutex m_registerMutex;
|
||||
std::mutex m_dataMutex;
|
||||
wpi::mutex m_registerMutex;
|
||||
wpi::mutex m_dataMutex;
|
||||
std::atomic<HAL_Bool> m_initialized{false};
|
||||
std::atomic<int64_t> m_accumulatorValue{false};
|
||||
std::shared_ptr<NotifyListenerVector> m_initializedCallbacks = nullptr;
|
||||
|
||||
@@ -23,7 +23,7 @@ class NotifierThread : public wpi::SafeThread {
|
||||
public:
|
||||
void Main() {
|
||||
int32_t status = 0;
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
std::unique_lock<wpi::mutex> lock(m_mutex);
|
||||
while (m_active) {
|
||||
startNotifierLoop:
|
||||
double waitTime = m_waitTime * 1e-6;
|
||||
|
||||
@@ -65,7 +65,7 @@ static std::string MakeStreamValue(llvm::StringRef address, int port) {
|
||||
|
||||
std::shared_ptr<nt::NetworkTable> CameraServer::GetSourceTable(
|
||||
CS_Source source) {
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
return m_tables.lookup(source);
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ std::vector<std::string> CameraServer::GetSourceStreamValues(CS_Source source) {
|
||||
}
|
||||
|
||||
void CameraServer::UpdateStreamValues() {
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
// Over all the sinks...
|
||||
for (const auto& i : m_sinks) {
|
||||
CS_Status status = 0;
|
||||
@@ -338,7 +338,7 @@ CameraServer::CameraServer()
|
||||
// Create subtable for the camera
|
||||
auto table = m_publishTable->GetSubTable(event.name);
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
m_tables.insert(std::make_pair(event.sourceHandle, table));
|
||||
}
|
||||
llvm::SmallString<64> buf;
|
||||
@@ -591,7 +591,7 @@ void CameraServer::StartAutomaticCapture(const cs::VideoSource& camera) {
|
||||
cs::CvSink CameraServer::GetVideo() {
|
||||
cs::VideoSource source;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
if (m_primarySourceName.empty()) {
|
||||
wpi_setWPIErrorWithContext(CameraServerError, "no camera available");
|
||||
return cs::CvSink{};
|
||||
@@ -611,7 +611,7 @@ cs::CvSink CameraServer::GetVideo(const cs::VideoSource& camera) {
|
||||
name += camera.GetName();
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
auto it = m_sinks.find(name);
|
||||
if (it != m_sinks.end()) {
|
||||
auto kind = it->second.GetKind();
|
||||
@@ -635,7 +635,7 @@ cs::CvSink CameraServer::GetVideo(const cs::VideoSource& camera) {
|
||||
cs::CvSink CameraServer::GetVideo(llvm::StringRef name) {
|
||||
cs::VideoSource source;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
auto it = m_sources.find(name);
|
||||
if (it == m_sources.end()) {
|
||||
llvm::SmallString<64> buf;
|
||||
@@ -659,7 +659,7 @@ cs::CvSource CameraServer::PutVideo(llvm::StringRef name, int width,
|
||||
cs::MjpegServer CameraServer::AddServer(llvm::StringRef name) {
|
||||
int port;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
port = m_nextPort++;
|
||||
}
|
||||
return AddServer(name, port);
|
||||
@@ -672,19 +672,19 @@ cs::MjpegServer CameraServer::AddServer(llvm::StringRef name, int port) {
|
||||
}
|
||||
|
||||
void CameraServer::AddServer(const cs::VideoSink& server) {
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
m_sinks.emplace_second(server.GetName(), server);
|
||||
}
|
||||
|
||||
void CameraServer::RemoveServer(llvm::StringRef name) {
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
m_sinks.erase(name);
|
||||
}
|
||||
|
||||
cs::VideoSink CameraServer::GetServer() {
|
||||
llvm::SmallString<64> name;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
if (m_primarySourceName.empty()) {
|
||||
wpi_setWPIErrorWithContext(CameraServerError, "no camera available");
|
||||
return cs::VideoSink{};
|
||||
@@ -696,7 +696,7 @@ cs::VideoSink CameraServer::GetServer() {
|
||||
}
|
||||
|
||||
cs::VideoSink CameraServer::GetServer(llvm::StringRef name) {
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
auto it = m_sinks.find(name);
|
||||
if (it == m_sinks.end()) {
|
||||
llvm::SmallString<64> buf;
|
||||
@@ -710,18 +710,18 @@ cs::VideoSink CameraServer::GetServer(llvm::StringRef name) {
|
||||
|
||||
void CameraServer::AddCamera(const cs::VideoSource& camera) {
|
||||
std::string name = camera.GetName();
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
if (m_primarySourceName.empty()) m_primarySourceName = name;
|
||||
m_sources.emplace_second(name, camera);
|
||||
}
|
||||
|
||||
void CameraServer::RemoveCamera(llvm::StringRef name) {
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
m_sources.erase(name);
|
||||
}
|
||||
|
||||
void CameraServer::SetSize(int size) {
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_mutex);
|
||||
if (m_primarySourceName.empty()) return;
|
||||
auto it = m_sources.find(m_primarySourceName);
|
||||
if (it == m_sources.end()) return;
|
||||
|
||||
@@ -40,7 +40,7 @@ void Scheduler::SetEnabled(bool enabled) { m_enabled = enabled; }
|
||||
* @param command The command to be scheduled
|
||||
*/
|
||||
void Scheduler::AddCommand(Command* command) {
|
||||
std::lock_guard<std::mutex> sync(m_additionsLock);
|
||||
std::lock_guard<wpi::mutex> sync(m_additionsLock);
|
||||
if (std::find(m_additions.begin(), m_additions.end(), command) !=
|
||||
m_additions.end())
|
||||
return;
|
||||
@@ -48,7 +48,7 @@ void Scheduler::AddCommand(Command* command) {
|
||||
}
|
||||
|
||||
void Scheduler::AddButton(ButtonScheduler* button) {
|
||||
std::lock_guard<std::mutex> sync(m_buttonsLock);
|
||||
std::lock_guard<wpi::mutex> sync(m_buttonsLock);
|
||||
m_buttons.push_back(button);
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ void Scheduler::Run() {
|
||||
{
|
||||
if (!m_enabled) return;
|
||||
|
||||
std::lock_guard<std::mutex> sync(m_buttonsLock);
|
||||
std::lock_guard<wpi::mutex> sync(m_buttonsLock);
|
||||
for (auto rButtonIter = m_buttons.rbegin(); rButtonIter != m_buttons.rend();
|
||||
rButtonIter++) {
|
||||
(*rButtonIter)->Execute();
|
||||
@@ -144,7 +144,7 @@ void Scheduler::Run() {
|
||||
|
||||
// Add the new things
|
||||
{
|
||||
std::lock_guard<std::mutex> sync(m_additionsLock);
|
||||
std::lock_guard<wpi::mutex> sync(m_additionsLock);
|
||||
for (auto additionsIter = m_additions.begin();
|
||||
additionsIter != m_additions.end(); additionsIter++) {
|
||||
ProcessCommandAddition(*additionsIter);
|
||||
|
||||
@@ -23,10 +23,10 @@ using namespace frc;
|
||||
|
||||
std::array<bool, 3> DigitalGlitchFilter::m_filterAllocated = {
|
||||
{false, false, false}};
|
||||
std::mutex DigitalGlitchFilter::m_mutex;
|
||||
wpi::mutex DigitalGlitchFilter::m_mutex;
|
||||
|
||||
DigitalGlitchFilter::DigitalGlitchFilter() {
|
||||
std::lock_guard<std::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
auto index =
|
||||
std::find(m_filterAllocated.begin(), m_filterAllocated.end(), false);
|
||||
wpi_assert(index != m_filterAllocated.end());
|
||||
@@ -39,7 +39,7 @@ DigitalGlitchFilter::DigitalGlitchFilter() {
|
||||
|
||||
DigitalGlitchFilter::~DigitalGlitchFilter() {
|
||||
if (m_channelIndex >= 0) {
|
||||
std::lock_guard<std::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
m_filterAllocated[m_channelIndex] = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ bool DriverStation::GetStickButton(int stick, int button) {
|
||||
"ERROR: Button indexes begin at 1 in WPILib for C++ and Java");
|
||||
return false;
|
||||
}
|
||||
std::unique_lock<std::mutex> lock(m_cacheDataMutex);
|
||||
std::unique_lock<wpi::mutex> lock(m_cacheDataMutex);
|
||||
if (button > m_joystickButtons[stick].count) {
|
||||
// Unlock early so error printing isn't locked.
|
||||
lock.unlock();
|
||||
@@ -134,7 +134,7 @@ bool DriverStation::GetStickButtonPressed(int stick, int button) {
|
||||
"ERROR: Button indexes begin at 1 in WPILib for C++ and Java");
|
||||
return false;
|
||||
}
|
||||
std::unique_lock<std::mutex> lock(m_cacheDataMutex);
|
||||
std::unique_lock<wpi::mutex> lock(m_cacheDataMutex);
|
||||
if (button > m_joystickButtons[stick].count) {
|
||||
// Unlock early so error printing isn't locked.
|
||||
lock.unlock();
|
||||
@@ -171,7 +171,7 @@ bool DriverStation::GetStickButtonReleased(int stick, int button) {
|
||||
"ERROR: Button indexes begin at 1 in WPILib for C++ and Java");
|
||||
return false;
|
||||
}
|
||||
std::unique_lock<std::mutex> lock(m_cacheDataMutex);
|
||||
std::unique_lock<wpi::mutex> lock(m_cacheDataMutex);
|
||||
if (button > m_joystickButtons[stick].count) {
|
||||
// Unlock early so error printing isn't locked.
|
||||
lock.unlock();
|
||||
@@ -204,7 +204,7 @@ double DriverStation::GetStickAxis(int stick, int axis) {
|
||||
wpi_setWPIError(BadJoystickIndex);
|
||||
return 0;
|
||||
}
|
||||
std::unique_lock<std::mutex> lock(m_cacheDataMutex);
|
||||
std::unique_lock<wpi::mutex> lock(m_cacheDataMutex);
|
||||
if (axis >= m_joystickAxes[stick].count) {
|
||||
// Unlock early so error printing isn't locked.
|
||||
m_cacheDataMutex.unlock();
|
||||
@@ -230,7 +230,7 @@ int DriverStation::GetStickPOV(int stick, int pov) {
|
||||
wpi_setWPIError(BadJoystickIndex);
|
||||
return -1;
|
||||
}
|
||||
std::unique_lock<std::mutex> lock(m_cacheDataMutex);
|
||||
std::unique_lock<wpi::mutex> lock(m_cacheDataMutex);
|
||||
if (pov >= m_joystickPOVs[stick].count) {
|
||||
// Unlock early so error printing isn't locked.
|
||||
lock.unlock();
|
||||
@@ -256,7 +256,7 @@ int DriverStation::GetStickButtons(int stick) const {
|
||||
wpi_setWPIError(BadJoystickIndex);
|
||||
return 0;
|
||||
}
|
||||
std::lock_guard<std::mutex> lock(m_cacheDataMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_cacheDataMutex);
|
||||
return m_joystickButtons[stick].buttons;
|
||||
}
|
||||
|
||||
@@ -271,7 +271,7 @@ int DriverStation::GetStickAxisCount(int stick) const {
|
||||
wpi_setWPIError(BadJoystickIndex);
|
||||
return 0;
|
||||
}
|
||||
std::lock_guard<std::mutex> lock(m_cacheDataMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_cacheDataMutex);
|
||||
return m_joystickAxes[stick].count;
|
||||
}
|
||||
|
||||
@@ -286,7 +286,7 @@ int DriverStation::GetStickPOVCount(int stick) const {
|
||||
wpi_setWPIError(BadJoystickIndex);
|
||||
return 0;
|
||||
}
|
||||
std::lock_guard<std::mutex> lock(m_cacheDataMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_cacheDataMutex);
|
||||
return m_joystickPOVs[stick].count;
|
||||
}
|
||||
|
||||
@@ -301,7 +301,7 @@ int DriverStation::GetStickButtonCount(int stick) const {
|
||||
wpi_setWPIError(BadJoystickIndex);
|
||||
return 0;
|
||||
}
|
||||
std::lock_guard<std::mutex> lock(m_cacheDataMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_cacheDataMutex);
|
||||
return m_joystickButtons[stick].count;
|
||||
}
|
||||
|
||||
@@ -316,7 +316,7 @@ bool DriverStation::GetJoystickIsXbox(int stick) const {
|
||||
wpi_setWPIError(BadJoystickIndex);
|
||||
return false;
|
||||
}
|
||||
std::lock_guard<std::mutex> lock(m_cacheDataMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_cacheDataMutex);
|
||||
return static_cast<bool>(m_joystickDescriptor[stick].isXbox);
|
||||
}
|
||||
|
||||
@@ -331,7 +331,7 @@ int DriverStation::GetJoystickType(int stick) const {
|
||||
wpi_setWPIError(BadJoystickIndex);
|
||||
return -1;
|
||||
}
|
||||
std::lock_guard<std::mutex> lock(m_cacheDataMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_cacheDataMutex);
|
||||
return static_cast<int>(m_joystickDescriptor[stick].type);
|
||||
}
|
||||
|
||||
@@ -345,7 +345,7 @@ std::string DriverStation::GetJoystickName(int stick) const {
|
||||
if (stick >= kJoystickPorts) {
|
||||
wpi_setWPIError(BadJoystickIndex);
|
||||
}
|
||||
std::lock_guard<std::mutex> lock(m_cacheDataMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_cacheDataMutex);
|
||||
std::string retVal(m_joystickDescriptor[stick].name);
|
||||
return retVal;
|
||||
}
|
||||
@@ -361,7 +361,7 @@ int DriverStation::GetJoystickAxisType(int stick, int axis) const {
|
||||
wpi_setWPIError(BadJoystickIndex);
|
||||
return -1;
|
||||
}
|
||||
std::lock_guard<std::mutex> lock(m_cacheDataMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_cacheDataMutex);
|
||||
return m_joystickDescriptor[stick].axisTypes[axis];
|
||||
}
|
||||
|
||||
@@ -482,27 +482,27 @@ bool DriverStation::IsBrownedOut() const {
|
||||
}
|
||||
|
||||
std::string DriverStation::GetGameSpecificMessage() const {
|
||||
std::lock_guard<std::mutex> lock(m_cacheDataMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_cacheDataMutex);
|
||||
return m_matchInfo->gameSpecificMessage;
|
||||
}
|
||||
|
||||
std::string DriverStation::GetEventName() const {
|
||||
std::lock_guard<std::mutex> lock(m_cacheDataMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_cacheDataMutex);
|
||||
return m_matchInfo->eventName;
|
||||
}
|
||||
|
||||
DriverStation::MatchType DriverStation::GetMatchType() const {
|
||||
std::lock_guard<std::mutex> lock(m_cacheDataMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_cacheDataMutex);
|
||||
return m_matchInfo->matchType;
|
||||
}
|
||||
|
||||
int DriverStation::GetMatchNumber() const {
|
||||
std::lock_guard<std::mutex> lock(m_cacheDataMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_cacheDataMutex);
|
||||
return m_matchInfo->matchNumber;
|
||||
}
|
||||
|
||||
int DriverStation::GetReplayNumber() const {
|
||||
std::lock_guard<std::mutex> lock(m_cacheDataMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_cacheDataMutex);
|
||||
return m_matchInfo->replayNumber;
|
||||
}
|
||||
|
||||
@@ -650,7 +650,7 @@ void DriverStation::GetData() {
|
||||
UpdateControlWord(true, controlWord);
|
||||
// Obtain a write lock on the data, swap the cached data into the
|
||||
// main data arrays
|
||||
std::lock_guard<std::mutex> lock(m_cacheDataMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_cacheDataMutex);
|
||||
|
||||
for (int32_t i = 0; i < kJoystickPorts; i++) {
|
||||
// If buttons weren't pressed and are now, set flags in m_buttonsPressed
|
||||
@@ -768,7 +768,7 @@ void DriverStation::Run() {
|
||||
void DriverStation::UpdateControlWord(bool force,
|
||||
HAL_ControlWord& controlWord) const {
|
||||
auto now = std::chrono::steady_clock::now();
|
||||
std::lock_guard<std::mutex> lock(m_controlWordMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_controlWordMutex);
|
||||
// Update every 50 ms or on force.
|
||||
if ((now - m_lastControlWordUpdate > std::chrono::milliseconds(50)) ||
|
||||
force) {
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
using namespace frc;
|
||||
|
||||
std::mutex ErrorBase::_globalErrorMutex;
|
||||
wpi::mutex ErrorBase::_globalErrorMutex;
|
||||
Error ErrorBase::_globalError;
|
||||
|
||||
ErrorBase::ErrorBase() { HAL_Initialize(500, 0); }
|
||||
@@ -68,7 +68,7 @@ void ErrorBase::SetErrnoError(llvm::StringRef contextMessage,
|
||||
m_error.Set(-1, err, filename, function, lineNumber, this);
|
||||
|
||||
// Update the global error if there is not one already set.
|
||||
std::lock_guard<std::mutex> mutex(_globalErrorMutex);
|
||||
std::lock_guard<wpi::mutex> mutex(_globalErrorMutex);
|
||||
if (_globalError.GetCode() == 0) {
|
||||
_globalError.Clone(m_error);
|
||||
}
|
||||
@@ -97,7 +97,7 @@ void ErrorBase::SetImaqError(int success, llvm::StringRef contextMessage,
|
||||
m_error.Set(success, err.str(), filename, function, lineNumber, this);
|
||||
|
||||
// Update the global error if there is not one already set.
|
||||
std::lock_guard<std::mutex> mutex(_globalErrorMutex);
|
||||
std::lock_guard<wpi::mutex> mutex(_globalErrorMutex);
|
||||
if (_globalError.GetCode() == 0) {
|
||||
_globalError.Clone(m_error);
|
||||
}
|
||||
@@ -122,7 +122,7 @@ void ErrorBase::SetError(Error::Code code, llvm::StringRef contextMessage,
|
||||
m_error.Set(code, contextMessage, filename, function, lineNumber, this);
|
||||
|
||||
// Update the global error if there is not one already set.
|
||||
std::lock_guard<std::mutex> mutex(_globalErrorMutex);
|
||||
std::lock_guard<wpi::mutex> mutex(_globalErrorMutex);
|
||||
if (_globalError.GetCode() == 0) {
|
||||
_globalError.Clone(m_error);
|
||||
}
|
||||
@@ -160,7 +160,7 @@ void ErrorBase::SetErrorRange(Error::Code code, int32_t minRange,
|
||||
delete[] buf;
|
||||
|
||||
// Update the global error if there is not one already set.
|
||||
std::lock_guard<std::mutex> mutex(_globalErrorMutex);
|
||||
std::lock_guard<wpi::mutex> mutex(_globalErrorMutex);
|
||||
if (_globalError.GetCode() == 0) {
|
||||
_globalError.Clone(m_error);
|
||||
}
|
||||
@@ -186,7 +186,7 @@ void ErrorBase::SetWPIError(llvm::StringRef errorMessage, Error::Code code,
|
||||
m_error.Set(code, err, filename, function, lineNumber, this);
|
||||
|
||||
// Update the global error if there is not one already set.
|
||||
std::lock_guard<std::mutex> mutex(_globalErrorMutex);
|
||||
std::lock_guard<wpi::mutex> mutex(_globalErrorMutex);
|
||||
if (_globalError.GetCode() == 0) {
|
||||
_globalError.Clone(m_error);
|
||||
}
|
||||
@@ -208,7 +208,7 @@ void ErrorBase::SetGlobalError(Error::Code code, llvm::StringRef contextMessage,
|
||||
llvm::StringRef function, int lineNumber) {
|
||||
// If there was an error
|
||||
if (code != 0) {
|
||||
std::lock_guard<std::mutex> mutex(_globalErrorMutex);
|
||||
std::lock_guard<wpi::mutex> mutex(_globalErrorMutex);
|
||||
|
||||
// Set the current error information for this object.
|
||||
_globalError.Set(code, contextMessage, filename, function, lineNumber,
|
||||
@@ -222,7 +222,7 @@ void ErrorBase::SetGlobalWPIError(llvm::StringRef errorMessage,
|
||||
llvm::StringRef function, int lineNumber) {
|
||||
std::string err = errorMessage.str() + ": " + contextMessage.str();
|
||||
|
||||
std::lock_guard<std::mutex> mutex(_globalErrorMutex);
|
||||
std::lock_guard<wpi::mutex> mutex(_globalErrorMutex);
|
||||
if (_globalError.GetCode() != 0) {
|
||||
_globalError.Clear();
|
||||
}
|
||||
@@ -233,6 +233,6 @@ void ErrorBase::SetGlobalWPIError(llvm::StringRef errorMessage,
|
||||
* Retrieve the current global error.
|
||||
*/
|
||||
Error& ErrorBase::GetGlobalError() {
|
||||
std::lock_guard<std::mutex> mutex(_globalErrorMutex);
|
||||
std::lock_guard<wpi::mutex> mutex(_globalErrorMutex);
|
||||
return _globalError;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
using namespace frc;
|
||||
|
||||
std::set<MotorSafetyHelper*> MotorSafetyHelper::m_helperList;
|
||||
std::mutex MotorSafetyHelper::m_listMutex;
|
||||
wpi::mutex MotorSafetyHelper::m_listMutex;
|
||||
|
||||
/**
|
||||
* The constructor for a MotorSafetyHelper object.
|
||||
@@ -38,12 +38,12 @@ MotorSafetyHelper::MotorSafetyHelper(MotorSafety* safeObject)
|
||||
m_expiration = DEFAULT_SAFETY_EXPIRATION;
|
||||
m_stopTime = Timer::GetFPGATimestamp();
|
||||
|
||||
std::lock_guard<std::mutex> sync(m_listMutex);
|
||||
std::lock_guard<wpi::mutex> sync(m_listMutex);
|
||||
m_helperList.insert(this);
|
||||
}
|
||||
|
||||
MotorSafetyHelper::~MotorSafetyHelper() {
|
||||
std::lock_guard<std::mutex> sync(m_listMutex);
|
||||
std::lock_guard<wpi::mutex> sync(m_listMutex);
|
||||
m_helperList.erase(this);
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ MotorSafetyHelper::~MotorSafetyHelper() {
|
||||
* Resets the timer on this object that is used to do the timeouts.
|
||||
*/
|
||||
void MotorSafetyHelper::Feed() {
|
||||
std::lock_guard<std::mutex> sync(m_syncMutex);
|
||||
std::lock_guard<wpi::mutex> sync(m_syncMutex);
|
||||
m_stopTime = Timer::GetFPGATimestamp() + m_expiration;
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ void MotorSafetyHelper::Feed() {
|
||||
* @param expirationTime The timeout value in seconds.
|
||||
*/
|
||||
void MotorSafetyHelper::SetExpiration(double expirationTime) {
|
||||
std::lock_guard<std::mutex> sync(m_syncMutex);
|
||||
std::lock_guard<wpi::mutex> sync(m_syncMutex);
|
||||
m_expiration = expirationTime;
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ void MotorSafetyHelper::SetExpiration(double expirationTime) {
|
||||
* @return the timeout value in seconds.
|
||||
*/
|
||||
double MotorSafetyHelper::GetExpiration() const {
|
||||
std::lock_guard<std::mutex> sync(m_syncMutex);
|
||||
std::lock_guard<wpi::mutex> sync(m_syncMutex);
|
||||
return m_expiration;
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ double MotorSafetyHelper::GetExpiration() const {
|
||||
* timed out.
|
||||
*/
|
||||
bool MotorSafetyHelper::IsAlive() const {
|
||||
std::lock_guard<std::mutex> sync(m_syncMutex);
|
||||
std::lock_guard<wpi::mutex> sync(m_syncMutex);
|
||||
return !m_enabled || m_stopTime > Timer::GetFPGATimestamp();
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ void MotorSafetyHelper::Check() {
|
||||
DriverStation& ds = DriverStation::GetInstance();
|
||||
if (!m_enabled || ds.IsDisabled() || ds.IsTest()) return;
|
||||
|
||||
std::lock_guard<std::mutex> sync(m_syncMutex);
|
||||
std::lock_guard<wpi::mutex> sync(m_syncMutex);
|
||||
if (m_stopTime < Timer::GetFPGATimestamp()) {
|
||||
llvm::SmallString<128> buf;
|
||||
llvm::raw_svector_ostream desc(buf);
|
||||
@@ -111,7 +111,7 @@ void MotorSafetyHelper::Check() {
|
||||
* @param enabled True if motor safety is enforced for this object
|
||||
*/
|
||||
void MotorSafetyHelper::SetSafetyEnabled(bool enabled) {
|
||||
std::lock_guard<std::mutex> sync(m_syncMutex);
|
||||
std::lock_guard<wpi::mutex> sync(m_syncMutex);
|
||||
m_enabled = enabled;
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ void MotorSafetyHelper::SetSafetyEnabled(bool enabled) {
|
||||
* @return True if motor safety is enforced for this device
|
||||
*/
|
||||
bool MotorSafetyHelper::IsSafetyEnabled() const {
|
||||
std::lock_guard<std::mutex> sync(m_syncMutex);
|
||||
std::lock_guard<wpi::mutex> sync(m_syncMutex);
|
||||
return m_enabled;
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ bool MotorSafetyHelper::IsSafetyEnabled() const {
|
||||
* any that have timed out.
|
||||
*/
|
||||
void MotorSafetyHelper::CheckMotors() {
|
||||
std::lock_guard<std::mutex> sync(m_listMutex);
|
||||
std::lock_guard<wpi::mutex> sync(m_listMutex);
|
||||
for (auto elem : m_helperList) {
|
||||
elem->Check();
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
using namespace frc;
|
||||
|
||||
std::mutex Notifier::m_destructorMutex;
|
||||
wpi::mutex Notifier::m_destructorMutex;
|
||||
|
||||
/**
|
||||
* Create a Notifier for timer event notification.
|
||||
@@ -45,8 +45,8 @@ Notifier::~Notifier() {
|
||||
/* Acquire the mutex; this makes certain that the handler is not being
|
||||
* executed by the interrupt manager.
|
||||
*/
|
||||
std::lock_guard<std::mutex> lockStatic(Notifier::m_destructorMutex);
|
||||
std::lock_guard<std::mutex> lock(m_processMutex);
|
||||
std::lock_guard<wpi::mutex> lockStatic(Notifier::m_destructorMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_processMutex);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -69,7 +69,7 @@ void Notifier::Notify(uint64_t currentTimeInt, HAL_NotifierHandle handle) {
|
||||
Notifier* notifier;
|
||||
{
|
||||
// Lock static mutex to grab the notifier param
|
||||
std::lock_guard<std::mutex> lock(Notifier::m_destructorMutex);
|
||||
std::lock_guard<wpi::mutex> lock(Notifier::m_destructorMutex);
|
||||
int32_t status = 0;
|
||||
auto notifierPointer = HAL_GetNotifierParam(handle, &status);
|
||||
if (notifierPointer == nullptr) return;
|
||||
@@ -96,7 +96,7 @@ void Notifier::Notify(uint64_t currentTimeInt, HAL_NotifierHandle handle) {
|
||||
* @param delay Seconds to wait before the handler is called.
|
||||
*/
|
||||
void Notifier::StartSingle(double delay) {
|
||||
std::lock_guard<std::mutex> sync(m_processMutex);
|
||||
std::lock_guard<wpi::mutex> sync(m_processMutex);
|
||||
m_periodic = false;
|
||||
m_period = delay;
|
||||
m_expirationTime = GetClock() + m_period;
|
||||
@@ -114,7 +114,7 @@ void Notifier::StartSingle(double delay) {
|
||||
* after the call to this method.
|
||||
*/
|
||||
void Notifier::StartPeriodic(double period) {
|
||||
std::lock_guard<std::mutex> sync(m_processMutex);
|
||||
std::lock_guard<wpi::mutex> sync(m_processMutex);
|
||||
m_periodic = true;
|
||||
m_period = period;
|
||||
m_expirationTime = GetClock() + m_period;
|
||||
@@ -137,6 +137,6 @@ void Notifier::Stop() {
|
||||
|
||||
// Wait for a currently executing handler to complete before returning from
|
||||
// Stop()
|
||||
std::lock_guard<std::mutex> lockStatic(Notifier::m_destructorMutex);
|
||||
std::lock_guard<std::mutex> lock(m_processMutex);
|
||||
std::lock_guard<wpi::mutex> lockStatic(Notifier::m_destructorMutex);
|
||||
std::lock_guard<wpi::mutex> lock(m_processMutex);
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ void PIDController::Calculate() {
|
||||
PIDOutput* pidOutput;
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
pidInput = m_pidInput;
|
||||
pidOutput = m_pidOutput;
|
||||
enabled = m_enabled;
|
||||
@@ -103,7 +103,7 @@ void PIDController::Calculate() {
|
||||
if (enabled) {
|
||||
double feedForward = CalculateFeedForward();
|
||||
|
||||
std::lock_guard<std::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
double input = pidInput->PIDGet();
|
||||
double result;
|
||||
PIDOutput* pidOutput;
|
||||
@@ -200,7 +200,7 @@ double PIDController::CalculateFeedForward() {
|
||||
*/
|
||||
void PIDController::SetPID(double p, double i, double d) {
|
||||
{
|
||||
std::lock_guard<std::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
m_P = p;
|
||||
m_I = i;
|
||||
m_D = d;
|
||||
@@ -223,7 +223,7 @@ void PIDController::SetPID(double p, double i, double d) {
|
||||
*/
|
||||
void PIDController::SetPID(double p, double i, double d, double f) {
|
||||
{
|
||||
std::lock_guard<std::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
m_P = p;
|
||||
m_I = i;
|
||||
m_D = d;
|
||||
@@ -242,7 +242,7 @@ void PIDController::SetPID(double p, double i, double d, double f) {
|
||||
* @return proportional coefficient
|
||||
*/
|
||||
double PIDController::GetP() const {
|
||||
std::lock_guard<std::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
return m_P;
|
||||
}
|
||||
|
||||
@@ -252,7 +252,7 @@ double PIDController::GetP() const {
|
||||
* @return integral coefficient
|
||||
*/
|
||||
double PIDController::GetI() const {
|
||||
std::lock_guard<std::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
return m_I;
|
||||
}
|
||||
|
||||
@@ -262,7 +262,7 @@ double PIDController::GetI() const {
|
||||
* @return differential coefficient
|
||||
*/
|
||||
double PIDController::GetD() const {
|
||||
std::lock_guard<std::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
return m_D;
|
||||
}
|
||||
|
||||
@@ -272,7 +272,7 @@ double PIDController::GetD() const {
|
||||
* @return Feed forward coefficient
|
||||
*/
|
||||
double PIDController::GetF() const {
|
||||
std::lock_guard<std::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
return m_F;
|
||||
}
|
||||
|
||||
@@ -284,7 +284,7 @@ double PIDController::GetF() const {
|
||||
* @return the latest calculated output
|
||||
*/
|
||||
double PIDController::Get() const {
|
||||
std::lock_guard<std::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
return m_result;
|
||||
}
|
||||
|
||||
@@ -298,7 +298,7 @@ double PIDController::Get() const {
|
||||
* @param continuous true turns on continuous, false turns off continuous
|
||||
*/
|
||||
void PIDController::SetContinuous(bool continuous) {
|
||||
std::lock_guard<std::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
m_continuous = continuous;
|
||||
}
|
||||
|
||||
@@ -310,7 +310,7 @@ void PIDController::SetContinuous(bool continuous) {
|
||||
*/
|
||||
void PIDController::SetInputRange(double minimumInput, double maximumInput) {
|
||||
{
|
||||
std::lock_guard<std::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
m_minimumInput = minimumInput;
|
||||
m_maximumInput = maximumInput;
|
||||
}
|
||||
@@ -325,7 +325,7 @@ void PIDController::SetInputRange(double minimumInput, double maximumInput) {
|
||||
* @param maximumOutput the maximum value to write to the output
|
||||
*/
|
||||
void PIDController::SetOutputRange(double minimumOutput, double maximumOutput) {
|
||||
std::lock_guard<std::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
m_minimumOutput = minimumOutput;
|
||||
m_maximumOutput = maximumOutput;
|
||||
}
|
||||
@@ -339,7 +339,7 @@ void PIDController::SetOutputRange(double minimumOutput, double maximumOutput) {
|
||||
*/
|
||||
void PIDController::SetSetpoint(double setpoint) {
|
||||
{
|
||||
std::lock_guard<std::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
|
||||
if (m_maximumInput > m_minimumInput) {
|
||||
if (setpoint > m_maximumInput)
|
||||
@@ -366,7 +366,7 @@ void PIDController::SetSetpoint(double setpoint) {
|
||||
* @return the current setpoint
|
||||
*/
|
||||
double PIDController::GetSetpoint() const {
|
||||
std::lock_guard<std::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
return m_setpoint;
|
||||
}
|
||||
|
||||
@@ -376,7 +376,7 @@ double PIDController::GetSetpoint() const {
|
||||
* @return the change in setpoint over time
|
||||
*/
|
||||
double PIDController::GetDeltaSetpoint() const {
|
||||
std::lock_guard<std::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
return (m_setpoint - m_prevSetpoint) / m_setpointTimer.Get();
|
||||
}
|
||||
|
||||
@@ -388,7 +388,7 @@ double PIDController::GetDeltaSetpoint() const {
|
||||
double PIDController::GetError() const {
|
||||
double setpoint = GetSetpoint();
|
||||
{
|
||||
std::lock_guard<std::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
return GetContinuousError(setpoint - m_pidInput->PIDGet());
|
||||
}
|
||||
}
|
||||
@@ -419,7 +419,7 @@ PIDSourceType PIDController::GetPIDSourceType() const {
|
||||
double PIDController::GetAvgError() const {
|
||||
double avgError = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
// Don't divide by zero.
|
||||
if (m_buf.size()) avgError = m_bufTotal / m_buf.size();
|
||||
}
|
||||
@@ -433,7 +433,7 @@ double PIDController::GetAvgError() const {
|
||||
* @param percentage error which is tolerable
|
||||
*/
|
||||
void PIDController::SetTolerance(double percent) {
|
||||
std::lock_guard<std::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
m_toleranceType = kPercentTolerance;
|
||||
m_tolerance = percent;
|
||||
}
|
||||
@@ -445,7 +445,7 @@ void PIDController::SetTolerance(double percent) {
|
||||
* @param percentage error which is tolerable
|
||||
*/
|
||||
void PIDController::SetAbsoluteTolerance(double absTolerance) {
|
||||
std::lock_guard<std::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
m_toleranceType = kAbsoluteTolerance;
|
||||
m_tolerance = absTolerance;
|
||||
}
|
||||
@@ -457,7 +457,7 @@ void PIDController::SetAbsoluteTolerance(double absTolerance) {
|
||||
* @param percentage error which is tolerable
|
||||
*/
|
||||
void PIDController::SetPercentTolerance(double percent) {
|
||||
std::lock_guard<std::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
m_toleranceType = kPercentTolerance;
|
||||
m_tolerance = percent;
|
||||
}
|
||||
@@ -473,7 +473,7 @@ void PIDController::SetPercentTolerance(double percent) {
|
||||
* @param bufLength Number of previous cycles to average. Defaults to 1.
|
||||
*/
|
||||
void PIDController::SetToleranceBuffer(int bufLength) {
|
||||
std::lock_guard<std::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
m_bufLength = bufLength;
|
||||
|
||||
// Cut the buffer down to size if needed.
|
||||
@@ -496,13 +496,13 @@ void PIDController::SetToleranceBuffer(int bufLength) {
|
||||
*/
|
||||
bool PIDController::OnTarget() const {
|
||||
{
|
||||
std::lock_guard<std::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
if (m_buf.size() == 0) return false;
|
||||
}
|
||||
|
||||
double error = GetAvgError();
|
||||
|
||||
std::lock_guard<std::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
switch (m_toleranceType) {
|
||||
case kPercentTolerance:
|
||||
return std::fabs(error) <
|
||||
@@ -523,7 +523,7 @@ bool PIDController::OnTarget() const {
|
||||
*/
|
||||
void PIDController::Enable() {
|
||||
{
|
||||
std::lock_guard<std::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
m_enabled = true;
|
||||
}
|
||||
|
||||
@@ -535,7 +535,7 @@ void PIDController::Enable() {
|
||||
*/
|
||||
void PIDController::Disable() {
|
||||
{
|
||||
std::lock_guard<std::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
m_pidOutput->PIDWrite(0);
|
||||
m_enabled = false;
|
||||
}
|
||||
@@ -547,7 +547,7 @@ void PIDController::Disable() {
|
||||
* Return true if PIDController is enabled.
|
||||
*/
|
||||
bool PIDController::IsEnabled() const {
|
||||
std::lock_guard<std::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
return m_enabled;
|
||||
}
|
||||
|
||||
@@ -557,7 +557,7 @@ bool PIDController::IsEnabled() const {
|
||||
void PIDController::Reset() {
|
||||
Disable();
|
||||
|
||||
std::lock_guard<std::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
m_prevError = 0;
|
||||
m_totalError = 0;
|
||||
m_result = 0;
|
||||
@@ -586,7 +586,7 @@ void PIDController::InitTable(std::shared_ptr<nt::NetworkTable> subtable) {
|
||||
m_pListener = m_pEntry.AddListener(
|
||||
[=](const nt::EntryNotification& event) {
|
||||
if (!event.value->IsDouble()) return;
|
||||
std::lock_guard<std::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
m_P = event.value->GetDouble();
|
||||
},
|
||||
NT_NOTIFY_NEW | NT_NOTIFY_UPDATE);
|
||||
@@ -594,7 +594,7 @@ void PIDController::InitTable(std::shared_ptr<nt::NetworkTable> subtable) {
|
||||
m_iListener = m_iEntry.AddListener(
|
||||
[=](const nt::EntryNotification& event) {
|
||||
if (!event.value->IsDouble()) return;
|
||||
std::lock_guard<std::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
m_I = event.value->GetDouble();
|
||||
},
|
||||
NT_NOTIFY_NEW | NT_NOTIFY_UPDATE);
|
||||
@@ -602,7 +602,7 @@ void PIDController::InitTable(std::shared_ptr<nt::NetworkTable> subtable) {
|
||||
m_dListener = m_dEntry.AddListener(
|
||||
[=](const nt::EntryNotification& event) {
|
||||
if (!event.value->IsDouble()) return;
|
||||
std::lock_guard<std::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
m_D = event.value->GetDouble();
|
||||
},
|
||||
NT_NOTIFY_NEW | NT_NOTIFY_UPDATE);
|
||||
@@ -610,7 +610,7 @@ void PIDController::InitTable(std::shared_ptr<nt::NetworkTable> subtable) {
|
||||
m_fListener = m_fEntry.AddListener(
|
||||
[=](const nt::EntryNotification& event) {
|
||||
if (!event.value->IsDouble()) return;
|
||||
std::lock_guard<std::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
m_F = event.value->GetDouble();
|
||||
},
|
||||
NT_NOTIFY_NEW | NT_NOTIFY_UPDATE);
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
using namespace frc;
|
||||
|
||||
std::mutex Resource::m_createMutex;
|
||||
wpi::mutex Resource::m_createMutex;
|
||||
|
||||
/**
|
||||
* Allocate storage for a new instance of Resource.
|
||||
@@ -38,7 +38,7 @@ Resource::Resource(uint32_t elements) {
|
||||
*/
|
||||
void Resource::CreateResourceObject(std::unique_ptr<Resource>& r,
|
||||
uint32_t elements) {
|
||||
std::lock_guard<std::mutex> sync(m_createMutex);
|
||||
std::lock_guard<wpi::mutex> sync(m_createMutex);
|
||||
if (!r) {
|
||||
r = std::make_unique<Resource>(elements);
|
||||
}
|
||||
@@ -52,7 +52,7 @@ void Resource::CreateResourceObject(std::unique_ptr<Resource>& r,
|
||||
* allocated.
|
||||
*/
|
||||
uint32_t Resource::Allocate(const std::string& resourceDesc) {
|
||||
std::lock_guard<std::mutex> sync(m_allocateMutex);
|
||||
std::lock_guard<wpi::mutex> sync(m_allocateMutex);
|
||||
for (uint32_t i = 0; i < m_isAllocated.size(); i++) {
|
||||
if (!m_isAllocated[i]) {
|
||||
m_isAllocated[i] = true;
|
||||
@@ -70,7 +70,7 @@ uint32_t Resource::Allocate(const std::string& resourceDesc) {
|
||||
* verified unallocated, then returned.
|
||||
*/
|
||||
uint32_t Resource::Allocate(uint32_t index, const std::string& resourceDesc) {
|
||||
std::lock_guard<std::mutex> sync(m_allocateMutex);
|
||||
std::lock_guard<wpi::mutex> sync(m_allocateMutex);
|
||||
if (index >= m_isAllocated.size()) {
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, resourceDesc);
|
||||
return std::numeric_limits<uint32_t>::max();
|
||||
@@ -91,7 +91,7 @@ uint32_t Resource::Allocate(uint32_t index, const std::string& resourceDesc) {
|
||||
* be reused somewhere else in the program.
|
||||
*/
|
||||
void Resource::Free(uint32_t index) {
|
||||
std::unique_lock<std::mutex> sync(m_allocateMutex);
|
||||
std::unique_lock<wpi::mutex> sync(m_allocateMutex);
|
||||
if (index == std::numeric_limits<uint32_t>::max()) return;
|
||||
if (index >= m_isAllocated.size()) {
|
||||
wpi_setWPIError(NotAllocated);
|
||||
|
||||
@@ -83,7 +83,7 @@ double Timer::Get() const {
|
||||
double result;
|
||||
double currentTime = GetFPGATimestamp();
|
||||
|
||||
std::lock_guard<std::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
if (m_running) {
|
||||
// If the current time is before the start time, then the FPGA clock
|
||||
// rolled over. Compensate by adding the ~71 minutes that it takes
|
||||
@@ -107,7 +107,7 @@ double Timer::Get() const {
|
||||
* now.
|
||||
*/
|
||||
void Timer::Reset() {
|
||||
std::lock_guard<std::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
m_accumulatedTime = 0;
|
||||
m_startTime = GetFPGATimestamp();
|
||||
}
|
||||
@@ -119,7 +119,7 @@ void Timer::Reset() {
|
||||
* relative to the system clock.
|
||||
*/
|
||||
void Timer::Start() {
|
||||
std::lock_guard<std::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
if (!m_running) {
|
||||
m_startTime = GetFPGATimestamp();
|
||||
m_running = true;
|
||||
@@ -136,7 +136,7 @@ void Timer::Start() {
|
||||
void Timer::Stop() {
|
||||
double temp = Get();
|
||||
|
||||
std::lock_guard<std::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
if (m_running) {
|
||||
m_accumulatedTime = temp;
|
||||
m_running = false;
|
||||
@@ -153,7 +153,7 @@ void Timer::Stop() {
|
||||
*/
|
||||
bool Timer::HasPeriodPassed(double period) {
|
||||
if (Get() > period) {
|
||||
std::lock_guard<std::mutex> sync(m_mutex);
|
||||
std::lock_guard<wpi::mutex> sync(m_mutex);
|
||||
// Advance the start time by the period.
|
||||
m_startTime += period;
|
||||
// Don't set it to the current time... we want to avoid drift.
|
||||
|
||||
@@ -11,13 +11,13 @@
|
||||
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <llvm/DenseMap.h>
|
||||
#include <llvm/StringMap.h>
|
||||
#include <llvm/StringRef.h>
|
||||
#include <support/mutex.h>
|
||||
|
||||
#include "ErrorBase.h"
|
||||
#include "cscore.h"
|
||||
@@ -300,7 +300,7 @@ class CameraServer : public ErrorBase {
|
||||
|
||||
static constexpr char const* kPublishName = "/CameraPublisher";
|
||||
|
||||
std::mutex m_mutex;
|
||||
wpi::mutex m_mutex;
|
||||
std::atomic<int> m_defaultUsbDevice;
|
||||
std::string m_primarySourceName;
|
||||
llvm::StringMap<cs::VideoSource> m_sources;
|
||||
|
||||
@@ -10,11 +10,12 @@
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <support/mutex.h>
|
||||
|
||||
#include "Commands/Command.h"
|
||||
#include "ErrorBase.h"
|
||||
#include "SmartDashboard/NamedSendable.h"
|
||||
@@ -53,11 +54,11 @@ class Scheduler : public ErrorBase, public NamedSendable {
|
||||
void ProcessCommandAddition(Command* command);
|
||||
|
||||
Command::SubsystemSet m_subsystems;
|
||||
std::mutex m_buttonsLock;
|
||||
wpi::mutex m_buttonsLock;
|
||||
typedef std::vector<ButtonScheduler*> ButtonVector;
|
||||
ButtonVector m_buttons;
|
||||
typedef std::vector<Command*> CommandVector;
|
||||
std::mutex m_additionsLock;
|
||||
wpi::mutex m_additionsLock;
|
||||
CommandVector m_additions;
|
||||
typedef std::set<Command*> CommandSet;
|
||||
CommandSet m_commands;
|
||||
|
||||
@@ -10,7 +10,8 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include <array>
|
||||
#include <mutex>
|
||||
|
||||
#include <support/mutex.h>
|
||||
|
||||
#include "DigitalSource.h"
|
||||
|
||||
@@ -51,7 +52,7 @@ class DigitalGlitchFilter : public SensorBase {
|
||||
void DoAdd(DigitalSource* input, int requested_index);
|
||||
|
||||
int m_channelIndex = -1;
|
||||
static std::mutex m_mutex;
|
||||
static wpi::mutex m_mutex;
|
||||
static std::array<bool, 3> m_filterAllocated;
|
||||
};
|
||||
|
||||
|
||||
@@ -10,12 +10,12 @@
|
||||
#include <array>
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
#include <HAL/DriverStation.h>
|
||||
#include <llvm/StringRef.h>
|
||||
#include <support/mutex.h>
|
||||
|
||||
#include "RobotState.h"
|
||||
#include "SensorBase.h"
|
||||
@@ -135,7 +135,7 @@ class DriverStation : public SensorBase, public RobotStateInterface {
|
||||
std::thread m_dsThread;
|
||||
std::atomic<bool> m_isRunning{false};
|
||||
|
||||
mutable std::mutex m_cacheDataMutex;
|
||||
mutable wpi::mutex m_cacheDataMutex;
|
||||
|
||||
// Robot state status variables
|
||||
bool m_userInDisabled = false;
|
||||
@@ -146,7 +146,7 @@ class DriverStation : public SensorBase, public RobotStateInterface {
|
||||
// Control word variables
|
||||
mutable HAL_ControlWord m_controlWordCache;
|
||||
mutable std::chrono::steady_clock::time_point m_lastControlWordUpdate;
|
||||
mutable std::mutex m_controlWordMutex;
|
||||
mutable wpi::mutex m_controlWordMutex;
|
||||
|
||||
double m_nextMessageTime = 0;
|
||||
};
|
||||
|
||||
@@ -7,9 +7,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <mutex>
|
||||
|
||||
#include <llvm/StringRef.h>
|
||||
#include <support/mutex.h>
|
||||
|
||||
#include "Base.h"
|
||||
#include "Error.h"
|
||||
@@ -115,7 +114,7 @@ class ErrorBase {
|
||||
protected:
|
||||
mutable Error m_error;
|
||||
// TODO: Replace globalError with a global list of all errors.
|
||||
static std::mutex _globalErrorMutex;
|
||||
static wpi::mutex _globalErrorMutex;
|
||||
static Error _globalError;
|
||||
};
|
||||
|
||||
|
||||
@@ -7,9 +7,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <mutex>
|
||||
#include <set>
|
||||
|
||||
#include <support/mutex.h>
|
||||
|
||||
#include "ErrorBase.h"
|
||||
|
||||
namespace frc {
|
||||
@@ -37,13 +38,13 @@ class MotorSafetyHelper : public ErrorBase {
|
||||
// the FPGA clock value when this motor has expired
|
||||
double m_stopTime;
|
||||
// protect accesses to the state for this object
|
||||
mutable std::mutex m_syncMutex;
|
||||
mutable wpi::mutex m_syncMutex;
|
||||
// the object that is using the helper
|
||||
MotorSafety* m_safeObject;
|
||||
// List of all existing MotorSafetyHelper objects.
|
||||
static std::set<MotorSafetyHelper*> m_helperList;
|
||||
// protect accesses to the list of helpers
|
||||
static std::mutex m_listMutex;
|
||||
static wpi::mutex m_listMutex;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
@@ -11,10 +11,10 @@
|
||||
|
||||
#include <atomic>
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
#include <utility>
|
||||
|
||||
#include <HAL/Notifier.h>
|
||||
#include <support/mutex.h>
|
||||
|
||||
#include "ErrorBase.h"
|
||||
|
||||
@@ -47,9 +47,9 @@ class Notifier : public ErrorBase {
|
||||
static void Notify(uint64_t currentTimeInt, HAL_NotifierHandle handle);
|
||||
|
||||
// used to constrain execution between destructors and callback
|
||||
static std::mutex m_destructorMutex;
|
||||
static wpi::mutex m_destructorMutex;
|
||||
// held while updating process information
|
||||
std::mutex m_processMutex;
|
||||
wpi::mutex m_processMutex;
|
||||
// HAL handle, atomic for proper destruction
|
||||
std::atomic<HAL_NotifierHandle> m_notifier{0};
|
||||
// address of the handler
|
||||
|
||||
@@ -9,10 +9,11 @@
|
||||
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <queue>
|
||||
#include <string>
|
||||
|
||||
#include <support/mutex.h>
|
||||
|
||||
#include "Base.h"
|
||||
#include "Controller.h"
|
||||
#include "LiveWindow/LiveWindow.h"
|
||||
@@ -147,7 +148,7 @@ class PIDController : public LiveWindowSendable, public PIDInterface {
|
||||
std::queue<double> m_buf;
|
||||
double m_bufTotal = 0;
|
||||
|
||||
mutable std::mutex m_mutex;
|
||||
mutable wpi::mutex m_mutex;
|
||||
|
||||
std::unique_ptr<Notifier> m_controlLoop;
|
||||
Timer m_setpointTimer;
|
||||
|
||||
@@ -10,10 +10,11 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <support/mutex.h>
|
||||
|
||||
#include "ErrorBase.h"
|
||||
|
||||
namespace frc {
|
||||
@@ -43,9 +44,9 @@ class Resource : public ErrorBase {
|
||||
|
||||
private:
|
||||
std::vector<bool> m_isAllocated;
|
||||
std::mutex m_allocateMutex;
|
||||
wpi::mutex m_allocateMutex;
|
||||
|
||||
static std::mutex m_createMutex;
|
||||
static wpi::mutex m_createMutex;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <mutex>
|
||||
#include <support/mutex.h>
|
||||
|
||||
#include "Base.h"
|
||||
|
||||
@@ -52,7 +52,7 @@ class Timer {
|
||||
double m_startTime = 0.0;
|
||||
double m_accumulatedTime = 0.0;
|
||||
bool m_running = false;
|
||||
mutable std::mutex m_mutex;
|
||||
mutable wpi::mutex m_mutex;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
@@ -1,270 +0,0 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2017 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include <HAL/cpp/priority_mutex.h> // NOLINT(build/include_order)
|
||||
|
||||
#include <atomic>
|
||||
#include <condition_variable>
|
||||
#include <thread>
|
||||
|
||||
#include "TestBench.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace wpilib {
|
||||
namespace testing {
|
||||
|
||||
using std::chrono::system_clock;
|
||||
|
||||
// Threading primitive used to notify many threads that a condition is now true.
|
||||
// The condition can not be cleared.
|
||||
class Notification {
|
||||
public:
|
||||
// Efficiently waits until the Notification has been notified once.
|
||||
void Wait() {
|
||||
std::unique_lock<hal::priority_mutex> lock(m_mutex);
|
||||
while (!m_set) {
|
||||
m_condition.wait(lock);
|
||||
}
|
||||
}
|
||||
// Sets the condition to true, and wakes all waiting threads.
|
||||
void Notify() {
|
||||
std::lock_guard<hal::priority_mutex> lock(m_mutex);
|
||||
m_set = true;
|
||||
m_condition.notify_all();
|
||||
}
|
||||
|
||||
private:
|
||||
// hal::priority_mutex used for the notification and to protect the bit.
|
||||
hal::priority_mutex m_mutex;
|
||||
// Condition for threads to sleep on.
|
||||
std::condition_variable_any m_condition;
|
||||
// Bool which is true when the notification has been notified.
|
||||
bool m_set = false;
|
||||
};
|
||||
|
||||
void SetProcessorAffinity(int32_t core_id) {
|
||||
cpu_set_t cpuset;
|
||||
CPU_ZERO(&cpuset);
|
||||
CPU_SET(core_id, &cpuset);
|
||||
|
||||
pthread_t current_thread = pthread_self();
|
||||
ASSERT_EQ(pthread_setaffinity_np(current_thread, sizeof(cpu_set_t), &cpuset),
|
||||
0);
|
||||
}
|
||||
|
||||
void SetThreadRealtimePriorityOrDie(int32_t priority) {
|
||||
struct sched_param param;
|
||||
// Set realtime priority for this thread
|
||||
param.sched_priority = priority + sched_get_priority_min(SCHED_RR);
|
||||
ASSERT_EQ(pthread_setschedparam(pthread_self(), SCHED_RR, ¶m), 0)
|
||||
<< ": Failed to set scheduler priority.";
|
||||
}
|
||||
|
||||
// This thread holds the mutex and spins until signaled to release it and stop.
|
||||
template <typename MutexType>
|
||||
class LowPriorityThread {
|
||||
public:
|
||||
explicit LowPriorityThread(MutexType* mutex)
|
||||
: m_mutex(mutex), m_hold_mutex(1), m_success(0) {}
|
||||
|
||||
void operator()() {
|
||||
SetProcessorAffinity(0);
|
||||
SetThreadRealtimePriorityOrDie(20);
|
||||
m_mutex->lock();
|
||||
m_started.Notify();
|
||||
while (m_hold_mutex.test_and_set()) {
|
||||
}
|
||||
m_mutex->unlock();
|
||||
m_success.store(1);
|
||||
}
|
||||
|
||||
void WaitForStartup() { m_started.Wait(); }
|
||||
void release_mutex() { m_hold_mutex.clear(); }
|
||||
bool success() { return m_success.load(); }
|
||||
|
||||
private:
|
||||
// hal::priority_mutex to grab and release.
|
||||
MutexType* m_mutex;
|
||||
Notification m_started;
|
||||
// Atomic type used to signal when the thread should unlock the mutex.
|
||||
// Using a mutex to protect something could cause other issues, and a delay
|
||||
// between setting and reading isn't a problem as long as the set is atomic.
|
||||
std::atomic_flag m_hold_mutex;
|
||||
std::atomic<int> m_success;
|
||||
};
|
||||
|
||||
// This thread spins forever until signaled to stop.
|
||||
class BusyWaitingThread {
|
||||
public:
|
||||
BusyWaitingThread() : m_run(1), m_success(0) {}
|
||||
|
||||
void operator()() {
|
||||
SetProcessorAffinity(0);
|
||||
SetThreadRealtimePriorityOrDie(21);
|
||||
system_clock::time_point start_time = system_clock::now();
|
||||
m_started.Notify();
|
||||
while (m_run.test_and_set()) {
|
||||
// Have the busy waiting thread time out after a while. If it times out,
|
||||
// the test failed.
|
||||
if (system_clock::now() - start_time > std::chrono::milliseconds(50)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
m_success.store(1);
|
||||
}
|
||||
|
||||
void quit() { m_run.clear(); }
|
||||
void WaitForStartup() { m_started.Wait(); }
|
||||
bool success() { return m_success.load(); }
|
||||
|
||||
private:
|
||||
// Use an atomic type to signal if the thread should be running or not. A
|
||||
// mutex could affect the scheduler, which isn't worth it. A delay between
|
||||
// setting and reading the new value is fine.
|
||||
std::atomic_flag m_run;
|
||||
|
||||
Notification m_started;
|
||||
|
||||
std::atomic<int> m_success;
|
||||
};
|
||||
|
||||
// This thread starts up, grabs the mutex, and then exits.
|
||||
template <typename MutexType>
|
||||
class HighPriorityThread {
|
||||
public:
|
||||
explicit HighPriorityThread(MutexType* mutex) : m_mutex(mutex) {}
|
||||
|
||||
void operator()() {
|
||||
SetProcessorAffinity(0);
|
||||
SetThreadRealtimePriorityOrDie(22);
|
||||
m_started.Notify();
|
||||
m_mutex->lock();
|
||||
m_success.store(1);
|
||||
}
|
||||
|
||||
void WaitForStartup() { m_started.Wait(); }
|
||||
bool success() { return m_success.load(); }
|
||||
|
||||
private:
|
||||
Notification m_started;
|
||||
MutexType* m_mutex;
|
||||
std::atomic<int> m_success{0};
|
||||
};
|
||||
|
||||
// Class to test a MutexType to see if it solves the priority inheritance
|
||||
// problem.
|
||||
//
|
||||
// To run the test, we need 3 threads, and then 1 thread to kick the test off.
|
||||
// The threads must all run on the same core, otherwise they wouldn't starve
|
||||
// eachother. The threads and their roles are as follows:
|
||||
//
|
||||
// Low priority thread:
|
||||
// Holds a lock that the high priority thread needs, and releases it upon
|
||||
// request.
|
||||
// Medium priority thread:
|
||||
// Hogs the processor so that the low priority thread will never run if it's
|
||||
// priority doesn't get bumped.
|
||||
// High priority thread:
|
||||
// Starts up and then goes to grab the lock that the low priority thread has.
|
||||
//
|
||||
// Control thread:
|
||||
// Sets the deadlock up so that it will happen 100% of the time by making sure
|
||||
// that each thread in order gets to the point that it needs to be at to cause
|
||||
// the deadlock.
|
||||
template <typename MutexType>
|
||||
class InversionTestRunner {
|
||||
public:
|
||||
void operator()() {
|
||||
// This thread must run at the highest priority or it can't coordinate the
|
||||
// inversion. This means that it can't busy wait or everything could
|
||||
// starve.
|
||||
SetThreadRealtimePriorityOrDie(23);
|
||||
|
||||
MutexType m;
|
||||
|
||||
// Start the lowest priority thread and wait until it holds the lock.
|
||||
LowPriorityThread<MutexType> low(&m);
|
||||
std::thread low_thread(std::ref(low));
|
||||
low.WaitForStartup();
|
||||
|
||||
// Start the busy waiting thread and let it get to the loop.
|
||||
BusyWaitingThread busy;
|
||||
std::thread busy_thread(std::ref(busy));
|
||||
busy.WaitForStartup();
|
||||
|
||||
// Start the high priority thread and let it become blocked on the lock.
|
||||
HighPriorityThread<MutexType> high(&m);
|
||||
std::thread high_thread(std::ref(high));
|
||||
high.WaitForStartup();
|
||||
// Startup and locking the mutex in the high priority thread aren't atomic,
|
||||
// but pretty close. Wait a bit to let it happen.
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
|
||||
// Release the mutex in the low priority thread. If done right, everything
|
||||
// should finish now.
|
||||
low.release_mutex();
|
||||
|
||||
// Wait for everything to finish and compute success.
|
||||
high_thread.join();
|
||||
busy.quit();
|
||||
busy_thread.join();
|
||||
low_thread.join();
|
||||
m_success = low.success() && busy.success() && high.success();
|
||||
}
|
||||
|
||||
bool success() { return m_success; }
|
||||
|
||||
private:
|
||||
bool m_success = false;
|
||||
};
|
||||
|
||||
// TODO: Fix roborio permissions to run as root.
|
||||
|
||||
// Priority inversion test.
|
||||
TEST(MutexTest, DISABLED_PriorityInversionTest) {
|
||||
InversionTestRunner<hal::priority_mutex> runner;
|
||||
std::thread runner_thread(std::ref(runner));
|
||||
runner_thread.join();
|
||||
EXPECT_TRUE(runner.success());
|
||||
}
|
||||
|
||||
// Verify that the non-priority inversion mutex doesn't pass the test.
|
||||
TEST(MutexTest, DISABLED_StdMutexPriorityInversionTest) {
|
||||
InversionTestRunner<std::mutex> runner;
|
||||
std::thread runner_thread(std::ref(runner));
|
||||
runner_thread.join();
|
||||
EXPECT_FALSE(runner.success());
|
||||
}
|
||||
|
||||
// Smoke test to make sure that mutexes lock and unlock.
|
||||
TEST(MutexTest, TryLock) {
|
||||
hal::priority_mutex m;
|
||||
m.lock();
|
||||
EXPECT_FALSE(m.try_lock());
|
||||
m.unlock();
|
||||
EXPECT_TRUE(m.try_lock());
|
||||
}
|
||||
|
||||
// Priority inversion test.
|
||||
TEST(MutexTest, DISABLED_ReentrantPriorityInversionTest) {
|
||||
InversionTestRunner<hal::priority_recursive_mutex> runner;
|
||||
std::thread runner_thread(std::ref(runner));
|
||||
runner_thread.join();
|
||||
EXPECT_TRUE(runner.success());
|
||||
}
|
||||
|
||||
// Smoke test to make sure that mutexes lock and unlock.
|
||||
TEST(MutexTest, ReentrantTryLock) {
|
||||
hal::priority_recursive_mutex m;
|
||||
m.lock();
|
||||
EXPECT_TRUE(m.try_lock());
|
||||
m.unlock();
|
||||
EXPECT_TRUE(m.try_lock());
|
||||
}
|
||||
|
||||
} // namespace testing
|
||||
} // namespace wpilib
|
||||
@@ -8,9 +8,10 @@
|
||||
#include <assert.h>
|
||||
#include <jni.h>
|
||||
#include <atomic>
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
|
||||
#include <support/mutex.h>
|
||||
|
||||
#include "HAL/cpp/Log.h"
|
||||
|
||||
#include "HAL/Interrupts.h"
|
||||
@@ -87,7 +88,7 @@ void InterruptThreadJNI::Main() {
|
||||
&args);
|
||||
if (rs != JNI_OK) return;
|
||||
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
std::unique_lock<wpi::mutex> lock(m_mutex);
|
||||
while (m_active) {
|
||||
m_cond.wait(lock, [&] { return !m_active || m_notify; });
|
||||
if (!m_active) break;
|
||||
|
||||
@@ -10,10 +10,9 @@
|
||||
#include <jni.h>
|
||||
#include <stdio.h>
|
||||
#include <atomic>
|
||||
#include <condition_variable>
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <support/mutex.h>
|
||||
#include "HALUtil.h"
|
||||
#include "HAL/cpp/Log.h"
|
||||
#include "edu_wpi_first_wpilibj_hal_NotifierJNI.h"
|
||||
@@ -86,7 +85,7 @@ void NotifierThreadJNI::Main() {
|
||||
jvm->AttachCurrentThreadAsDaemon(reinterpret_cast<void **>(&env), &args);
|
||||
if (rs != JNI_OK) return;
|
||||
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
std::unique_lock<wpi::mutex> lock(m_mutex);
|
||||
while (m_active) {
|
||||
m_cond.wait(lock, [&] { return !m_active || m_notify; });
|
||||
if (!m_active) break;
|
||||
|
||||
Reference in New Issue
Block a user