mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-25 01: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;
|
||||
|
||||
Reference in New Issue
Block a user