Cleaned up variable names for std::lock_guard and their associated mutexes (#759)

This commit is contained in:
Tyler Veness
2017-11-22 17:10:21 -08:00
committed by Peter Johnson
parent 96de0b5b11
commit ba879f4663
22 changed files with 136 additions and 137 deletions

View File

@@ -229,7 +229,7 @@ int32_t HAL_GetAnalogValue(HAL_AnalogInputHandle analogPortHandle,
readSelect.Channel = port->channel;
readSelect.Averaged = false;
std::lock_guard<wpi::mutex> sync(analogRegisterWindowMutex);
std::lock_guard<wpi::mutex> lock(analogRegisterWindowMutex);
analogInputSystem->writeReadSelect(readSelect, status);
analogInputSystem->strobeLatchOutput(status);
return static_cast<int16_t>(analogInputSystem->readOutput(status));
@@ -260,7 +260,7 @@ int32_t HAL_GetAnalogAverageValue(HAL_AnalogInputHandle analogPortHandle,
readSelect.Channel = port->channel;
readSelect.Averaged = true;
std::lock_guard<wpi::mutex> sync(analogRegisterWindowMutex);
std::lock_guard<wpi::mutex> lock(analogRegisterWindowMutex);
analogInputSystem->writeReadSelect(readSelect, status);
analogInputSystem->strobeLatchOutput(status);
return static_cast<int32_t>(analogInputSystem->readOutput(status));

View File

@@ -36,7 +36,7 @@ bool analogSampleRateSet = false;
*/
void initializeAnalog(int32_t* status) {
if (analogSystemInitialized) return;
std::lock_guard<wpi::mutex> sync(analogRegisterWindowMutex);
std::lock_guard<wpi::mutex> lock(analogRegisterWindowMutex);
if (analogSystemInitialized) return;
analogInputSystem.reset(tAI::create(status));
analogOutputSystem.reset(tAO::create(status));

View File

@@ -54,7 +54,7 @@ HAL_DigitalHandle HAL_InitializeDIOPort(HAL_PortHandle portHandle,
port->channel = static_cast<uint8_t>(channel);
std::lock_guard<wpi::mutex> sync(digitalDIOMutex);
std::lock_guard<wpi::mutex> lock(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<wpi::mutex> sync(digitalDIOMutex);
std::lock_guard<wpi::mutex> lock(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<wpi::mutex> sync(digitalPwmMutex);
std::lock_guard<wpi::mutex> lock(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<wpi::mutex> sync(digitalDIOMutex);
std::lock_guard<wpi::mutex> lock(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<wpi::mutex> sync(digitalDIOMutex);
std::lock_guard<wpi::mutex> lock(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<wpi::mutex> sync(digitalDIOMutex);
std::lock_guard<wpi::mutex> lock(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<wpi::mutex> sync(digitalDIOMutex);
std::lock_guard<wpi::mutex> lock(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<wpi::mutex> sync(digitalDIOMutex);
std::lock_guard<wpi::mutex> lock(digitalDIOMutex);
hdrPeriod = digitalSystem->readFilterPeriodHdr(filterIndex, status);
if (*status == 0) {
mxpPeriod = digitalSystem->readFilterPeriodMXP(filterIndex, status);

View File

@@ -49,7 +49,7 @@ void HAL_InitializeI2C(HAL_I2CPort port, int32_t* status) {
}
if (port == 0) {
std::lock_guard<wpi::mutex> sync(digitalI2COnBoardMutex);
std::lock_guard<wpi::mutex> lock(digitalI2COnBoardMutex);
i2COnboardObjCount++;
if (i2COnboardObjCount > 1) return;
int handle = open("/dev/i2c-2", O_RDWR);
@@ -59,7 +59,7 @@ void HAL_InitializeI2C(HAL_I2CPort port, int32_t* status) {
}
i2COnBoardHandle = handle;
} else {
std::lock_guard<wpi::mutex> sync(digitalI2CMXPMutex);
std::lock_guard<wpi::mutex> lock(digitalI2CMXPMutex);
i2CMXPObjCount++;
if (i2CMXPObjCount > 1) return;
if ((i2CMXPDigitalHandle1 = HAL_InitializeDIOPort(
@@ -117,10 +117,10 @@ int32_t HAL_TransactionI2C(HAL_I2CPort port, int32_t deviceAddress,
rdwr.nmsgs = 2;
if (port == 0) {
std::lock_guard<wpi::mutex> sync(digitalI2COnBoardMutex);
std::lock_guard<wpi::mutex> lock(digitalI2COnBoardMutex);
return ioctl(i2COnBoardHandle, I2C_RDWR, &rdwr);
} else {
std::lock_guard<wpi::mutex> sync(digitalI2CMXPMutex);
std::lock_guard<wpi::mutex> lock(digitalI2CMXPMutex);
return ioctl(i2CMXPHandle, I2C_RDWR, &rdwr);
}
}
@@ -154,10 +154,10 @@ int32_t HAL_WriteI2C(HAL_I2CPort port, int32_t deviceAddress,
rdwr.nmsgs = 1;
if (port == 0) {
std::lock_guard<wpi::mutex> sync(digitalI2COnBoardMutex);
std::lock_guard<wpi::mutex> lock(digitalI2COnBoardMutex);
return ioctl(i2COnBoardHandle, I2C_RDWR, &rdwr);
} else {
std::lock_guard<wpi::mutex> sync(digitalI2CMXPMutex);
std::lock_guard<wpi::mutex> lock(digitalI2CMXPMutex);
return ioctl(i2CMXPHandle, I2C_RDWR, &rdwr);
}
}
@@ -193,10 +193,10 @@ int32_t HAL_ReadI2C(HAL_I2CPort port, int32_t deviceAddress, uint8_t* buffer,
rdwr.nmsgs = 1;
if (port == 0) {
std::lock_guard<wpi::mutex> sync(digitalI2COnBoardMutex);
std::lock_guard<wpi::mutex> lock(digitalI2COnBoardMutex);
return ioctl(i2COnBoardHandle, I2C_RDWR, &rdwr);
} else {
std::lock_guard<wpi::mutex> sync(digitalI2CMXPMutex);
std::lock_guard<wpi::mutex> lock(digitalI2CMXPMutex);
return ioctl(i2CMXPHandle, I2C_RDWR, &rdwr);
}
}
@@ -208,12 +208,12 @@ void HAL_CloseI2C(HAL_I2CPort port) {
}
if (port == 0) {
std::lock_guard<wpi::mutex> sync(digitalI2COnBoardMutex);
std::lock_guard<wpi::mutex> lock(digitalI2COnBoardMutex);
if (i2COnboardObjCount-- == 0) {
close(i2COnBoardHandle);
}
} else {
std::lock_guard<wpi::mutex> sync(digitalI2CMXPMutex);
std::lock_guard<wpi::mutex> lock(digitalI2CMXPMutex);
if (i2CMXPObjCount-- == 0) {
close(i2CMXPHandle);
}

View File

@@ -66,7 +66,7 @@ class NotifierHandleContainer
static NotifierHandleContainer notifierHandles;
static void alarmCallback(uint32_t, void*) {
std::lock_guard<wpi::mutex> sync(notifierMutex);
std::lock_guard<wpi::mutex> lock(notifierMutex);
int32_t status = 0;
uint64_t currentTime = 0;
@@ -109,7 +109,7 @@ HAL_NotifierHandle HAL_InitializeNotifier(int32_t* status) {
std::atexit(cleanupNotifierAtExit);
if (notifierRefCount.fetch_add(1) == 0) {
std::lock_guard<wpi::mutex> sync(notifierMutex);
std::lock_guard<wpi::mutex> lock(notifierMutex);
// create manager and alarm if not already created
if (!notifierManager) {
notifierManager = std::make_unique<tInterruptManager>(
@@ -156,7 +156,7 @@ void HAL_CleanNotifier(HAL_NotifierHandle notifierHandle, int32_t* status) {
notifier->cond.notify_all();
if (notifierRefCount.fetch_sub(1) == 1) {
std::lock_guard<wpi::mutex> sync(notifierMutex);
std::lock_guard<wpi::mutex> lock(notifierMutex);
// if this was the last notifier, clean up alarm and manager
if (notifierAlarm) {
notifierAlarm->writeEnable(false, status);
@@ -181,7 +181,7 @@ void HAL_UpdateNotifierAlarm(HAL_NotifierHandle notifierHandle,
notifier->triggeredTime = UINT64_MAX;
}
std::lock_guard<wpi::mutex> sync(notifierMutex);
std::lock_guard<wpi::mutex> lock(notifierMutex);
// Update alarm time if closer than current.
if (triggerTime < closestTrigger) {
bool wasActive = (closestTrigger != UINT64_MAX);

View File

@@ -92,7 +92,7 @@ void HAL_SetRelay(HAL_RelayHandle relayPortHandle, HAL_Bool on,
*status = HAL_HANDLE_ERROR;
return;
}
std::lock_guard<wpi::mutex> sync(digitalRelayMutex);
std::lock_guard<wpi::mutex> lock(digitalRelayMutex);
uint8_t relays = 0;
if (port->fwd) {
relays = relaySystem->readValue_Forward(status);

View File

@@ -273,7 +273,7 @@ int32_t HAL_TransactionSPI(HAL_SPIPort port, const uint8_t* dataToSend,
xfer.rx_buf = (__u64)dataReceived;
xfer.len = size;
std::lock_guard<wpi::mutex> sync(spiApiMutexes[port]);
std::lock_guard<wpi::mutex> lock(spiApiMutexes[port]);
return ioctl(HAL_GetSPIHandle(port), SPI_IOC_MESSAGE(1), &xfer);
}
@@ -298,7 +298,7 @@ int32_t HAL_WriteSPI(HAL_SPIPort port, const uint8_t* dataToSend,
xfer.tx_buf = (__u64)dataToSend;
xfer.len = sendSize;
std::lock_guard<wpi::mutex> sync(spiApiMutexes[port]);
std::lock_guard<wpi::mutex> lock(spiApiMutexes[port]);
return ioctl(HAL_GetSPIHandle(port), SPI_IOC_MESSAGE(1), &xfer);
}
@@ -325,7 +325,7 @@ int32_t HAL_ReadSPI(HAL_SPIPort port, uint8_t* buffer, int32_t count) {
xfer.rx_buf = (__u64)buffer;
xfer.len = count;
std::lock_guard<wpi::mutex> sync(spiApiMutexes[port]);
std::lock_guard<wpi::mutex> lock(spiApiMutexes[port]);
return ioctl(HAL_GetSPIHandle(port), SPI_IOC_MESSAGE(1), &xfer);
}
@@ -343,7 +343,7 @@ void HAL_CloseSPI(HAL_SPIPort port) {
HAL_FreeSPIAccumulator(port, &status);
{
std::lock_guard<wpi::mutex> sync(spiApiMutexes[port]);
std::lock_guard<wpi::mutex> lock(spiApiMutexes[port]);
close(HAL_GetSPIHandle(port));
}
@@ -385,7 +385,7 @@ void HAL_SetSPISpeed(HAL_SPIPort port, int32_t speed) {
return;
}
std::lock_guard<wpi::mutex> sync(spiApiMutexes[port]);
std::lock_guard<wpi::mutex> lock(spiApiMutexes[port]);
ioctl(HAL_GetSPIHandle(port), SPI_IOC_WR_MAX_SPEED_HZ, &speed);
}
@@ -410,7 +410,7 @@ void HAL_SetSPIOpts(HAL_SPIPort port, HAL_Bool msbFirst,
mode |= (clkIdleHigh ? 2 : 0);
mode |= (sampleOnTrailing ? 1 : 0);
std::lock_guard<wpi::mutex> sync(spiApiMutexes[port]);
std::lock_guard<wpi::mutex> lock(spiApiMutexes[port]);
ioctl(HAL_GetSPIHandle(port), SPI_IOC_WR_MODE, &mode);
}
@@ -425,7 +425,7 @@ void HAL_SetSPIChipSelectActiveHigh(HAL_SPIPort port, int32_t* status) {
return;
}
std::lock_guard<wpi::mutex> sync(spiApiMutexes[port]);
std::lock_guard<wpi::mutex> lock(spiApiMutexes[port]);
if (port < 4) {
spiSystem->writeChipSelectActiveHigh_Hdr(
spiSystem->readChipSelectActiveHigh_Hdr(status) | (1 << port), status);
@@ -445,7 +445,7 @@ void HAL_SetSPIChipSelectActiveLow(HAL_SPIPort port, int32_t* status) {
return;
}
std::lock_guard<wpi::mutex> sync(spiApiMutexes[port]);
std::lock_guard<wpi::mutex> lock(spiApiMutexes[port]);
if (port < 4) {
spiSystem->writeChipSelectActiveHigh_Hdr(
spiSystem->readChipSelectActiveHigh_Hdr(status) & ~(1 << port), status);
@@ -465,7 +465,7 @@ int32_t HAL_GetSPIHandle(HAL_SPIPort port) {
return 0;
}
std::lock_guard<wpi::mutex> sync(spiHandleMutexes[port]);
std::lock_guard<wpi::mutex> lock(spiHandleMutexes[port]);
switch (port) {
case 0:
return m_spiCS0Handle;
@@ -494,7 +494,7 @@ void HAL_SetSPIHandle(HAL_SPIPort port, int32_t handle) {
return;
}
std::lock_guard<wpi::mutex> sync(spiHandleMutexes[port]);
std::lock_guard<wpi::mutex> lock(spiHandleMutexes[port]);
switch (port) {
case 0:
m_spiCS0Handle = handle;
@@ -589,7 +589,7 @@ void HAL_InitSPIAccumulator(HAL_SPIPort port, int32_t period, int32_t cmd,
return;
}
std::lock_guard<wpi::mutex> sync(spiAccumulatorMutexes[port]);
std::lock_guard<wpi::mutex> lock(spiAccumulatorMutexes[port]);
if (!spiAccumulators[port])
spiAccumulators[port] = std::make_unique<SPIAccumulator>();
SPIAccumulator* accum = spiAccumulators[port].get();
@@ -643,7 +643,7 @@ void HAL_FreeSPIAccumulator(HAL_SPIPort port, int32_t* status) {
return;
}
std::lock_guard<wpi::mutex> sync(spiAccumulatorMutexes[port]);
std::lock_guard<wpi::mutex> lock(spiAccumulatorMutexes[port]);
SPIAccumulator* accum = spiAccumulators[port].get();
if (!accum) {
*status = NULL_PARAMETER;
@@ -663,7 +663,7 @@ void HAL_ResetSPIAccumulator(HAL_SPIPort port, int32_t* status) {
return;
}
std::lock_guard<wpi::mutex> sync(spiApiMutexes[port]);
std::lock_guard<wpi::mutex> lock(spiApiMutexes[port]);
SPIAccumulator* accum = spiAccumulators[port].get();
if (!accum) {
*status = NULL_PARAMETER;
@@ -690,7 +690,7 @@ void HAL_SetSPIAccumulatorCenter(HAL_SPIPort port, int32_t center,
return;
}
std::lock_guard<wpi::mutex> sync(spiAccumulatorMutexes[port]);
std::lock_guard<wpi::mutex> lock(spiAccumulatorMutexes[port]);
SPIAccumulator* accum = spiAccumulators[port].get();
if (!accum) {
*status = NULL_PARAMETER;
@@ -709,7 +709,7 @@ void HAL_SetSPIAccumulatorDeadband(HAL_SPIPort port, int32_t deadband,
return;
}
std::lock_guard<wpi::mutex> sync(spiAccumulatorMutexes[port]);
std::lock_guard<wpi::mutex> lock(spiAccumulatorMutexes[port]);
SPIAccumulator* accum = spiAccumulators[port].get();
if (!accum) {
*status = NULL_PARAMETER;
@@ -727,7 +727,7 @@ int32_t HAL_GetSPIAccumulatorLastValue(HAL_SPIPort port, int32_t* status) {
return 0;
}
std::lock_guard<wpi::mutex> sync(spiAccumulatorMutexes[port]);
std::lock_guard<wpi::mutex> lock(spiAccumulatorMutexes[port]);
SPIAccumulator* accum = spiAccumulators[port].get();
if (!accum) {
*status = NULL_PARAMETER;
@@ -747,7 +747,7 @@ int64_t HAL_GetSPIAccumulatorValue(HAL_SPIPort port, int32_t* status) {
return 0;
}
std::lock_guard<wpi::mutex> sync(spiAccumulatorMutexes[port]);
std::lock_guard<wpi::mutex> lock(spiAccumulatorMutexes[port]);
SPIAccumulator* accum = spiAccumulators[port].get();
if (!accum) {
*status = NULL_PARAMETER;
@@ -770,7 +770,7 @@ int64_t HAL_GetSPIAccumulatorCount(HAL_SPIPort port, int32_t* status) {
return 0;
}
std::lock_guard<wpi::mutex> sync(spiAccumulatorMutexes[port]);
std::lock_guard<wpi::mutex> lock(spiAccumulatorMutexes[port]);
SPIAccumulator* accum = spiAccumulators[port].get();
if (!accum) {
*status = NULL_PARAMETER;
@@ -813,7 +813,7 @@ void HAL_GetSPIAccumulatorOutput(HAL_SPIPort port, int64_t* value,
return;
}
std::lock_guard<wpi::mutex> sync(spiAccumulatorMutexes[port]);
std::lock_guard<wpi::mutex> lock(spiAccumulatorMutexes[port]);
SPIAccumulator* accum = spiAccumulators[port].get();
if (!accum) {
*status = NULL_PARAMETER;

View File

@@ -60,7 +60,7 @@ THandle DigitalHandleResource<THandle, TStruct, size>::Allocate(
*status = RESOURCE_OUT_OF_RANGE;
return HAL_kInvalidHandle;
}
std::lock_guard<wpi::mutex> sync(m_handleMutexes[index]);
std::lock_guard<wpi::mutex> lock(m_handleMutexes[index]);
// check for allocation, otherwise allocate and return a valid handle
if (m_structures[index] != nullptr) {
*status = RESOURCE_IS_ALLOCATED;
@@ -78,7 +78,7 @@ std::shared_ptr<TStruct> DigitalHandleResource<THandle, TStruct, size>::Get(
if (index < 0 || index >= size) {
return nullptr;
}
std::lock_guard<wpi::mutex> sync(m_handleMutexes[index]);
std::lock_guard<wpi::mutex> lock(m_handleMutexes[index]);
// return structure. Null will propogate correctly, so no need to manually
// check.
return m_structures[index];
@@ -91,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<wpi::mutex> sync(m_handleMutexes[index]);
std::lock_guard<wpi::mutex> lock(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<wpi::mutex> sync(m_handleMutexes[i]);
std::lock_guard<wpi::mutex> lock(m_handleMutexes[i]);
m_structures[i].reset();
}
HandleBase::ResetHandles();

View File

@@ -17,7 +17,6 @@
#include "HAL/Errors.h"
#include "HAL/Types.h"
#include "HAL/cpp/make_unique.h"
#include "HAL/cpp/priority_mutex.h"
#include "HAL/handles/HandlesInternal.h"
namespace hal {
@@ -74,7 +73,7 @@ IndexedClassedHandleResource<THandle, TStruct, size, enumValue>::Allocate(
*status = RESOURCE_OUT_OF_RANGE;
return HAL_kInvalidHandle;
}
std::lock_guard<wpi::mutex> sync(m_handleMutexes[index]);
std::lock_guard<wpi::mutex> lock(m_handleMutexes[index]);
// check for allocation, otherwise allocate and return a valid handle
if (m_structures[index] != nullptr) {
*status = RESOURCE_IS_ALLOCATED;
@@ -94,7 +93,7 @@ IndexedClassedHandleResource<THandle, TStruct, size, enumValue>::Get(
if (index < 0 || index >= size) {
return nullptr;
}
std::lock_guard<wpi::mutex> sync(m_handleMutexes[index]);
std::lock_guard<wpi::mutex> lock(m_handleMutexes[index]);
// return structure. Null will propogate correctly, so no need to manually
// check.
return m_structures[index];
@@ -108,7 +107,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<wpi::mutex> sync(m_handleMutexes[index]);
std::lock_guard<wpi::mutex> lock(m_handleMutexes[index]);
m_structures[index].reset();
}
@@ -117,7 +116,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<wpi::mutex> sync(m_handleMutexes[i]);
std::lock_guard<wpi::mutex> lock(m_handleMutexes[i]);
m_structures[i].reset();
}
HandleBase::ResetHandles();

View File

@@ -62,7 +62,7 @@ THandle IndexedHandleResource<THandle, TStruct, size, enumValue>::Allocate(
*status = RESOURCE_OUT_OF_RANGE;
return HAL_kInvalidHandle;
}
std::lock_guard<wpi::mutex> sync(m_handleMutexes[index]);
std::lock_guard<wpi::mutex> lock(m_handleMutexes[index]);
// check for allocation, otherwise allocate and return a valid handle
if (m_structures[index] != nullptr) {
*status = RESOURCE_IS_ALLOCATED;
@@ -81,7 +81,7 @@ IndexedHandleResource<THandle, TStruct, size, enumValue>::Get(THandle handle) {
if (index < 0 || index >= size) {
return nullptr;
}
std::lock_guard<wpi::mutex> sync(m_handleMutexes[index]);
std::lock_guard<wpi::mutex> lock(m_handleMutexes[index]);
// return structure. Null will propogate correctly, so no need to manually
// check.
return m_structures[index];
@@ -95,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<wpi::mutex> sync(m_handleMutexes[index]);
std::lock_guard<wpi::mutex> lock(m_handleMutexes[index]);
m_structures[index].reset();
}
@@ -103,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<wpi::mutex> sync(m_handleMutexes[i]);
std::lock_guard<wpi::mutex> lock(m_handleMutexes[i]);
m_structures[i].reset();
}
HandleBase::ResetHandles();

View File

@@ -59,12 +59,12 @@ THandle
LimitedClassedHandleResource<THandle, TStruct, size, enumValue>::Allocate(
std::shared_ptr<TStruct> toSet) {
// globally lock to loop through indices
std::lock_guard<wpi::mutex> sync(m_allocateMutex);
std::lock_guard<wpi::mutex> lock(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<wpi::mutex> sync(m_handleMutexes[i]);
std::lock_guard<wpi::mutex> lock(m_handleMutexes[i]);
m_structures[i] = toSet;
return static_cast<THandle>(createHandle(i, enumValue, m_version));
}
@@ -82,7 +82,7 @@ LimitedClassedHandleResource<THandle, TStruct, size, enumValue>::Get(
if (index < 0 || index >= size) {
return nullptr;
}
std::lock_guard<wpi::mutex> sync(m_handleMutexes[index]);
std::lock_guard<wpi::mutex> lock(m_handleMutexes[index]);
// return structure. Null will propogate correctly, so no need to manually
// check.
return m_structures[index];
@@ -96,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<wpi::mutex> sync(m_allocateMutex);
std::lock_guard<wpi::mutex> lock(m_handleMutexes[index]);
std::lock_guard<wpi::mutex> allocateLock(m_allocateMutex);
std::lock_guard<wpi::mutex> handleLock(m_handleMutexes[index]);
m_structures[index].reset();
}
@@ -106,9 +106,9 @@ template <typename THandle, typename TStruct, int16_t size,
void LimitedClassedHandleResource<THandle, TStruct, size,
enumValue>::ResetHandles() {
{
std::lock_guard<wpi::mutex> lock(m_allocateMutex);
std::lock_guard<wpi::mutex> allocateLock(m_allocateMutex);
for (int i = 0; i < size; i++) {
std::lock_guard<wpi::mutex> sync(m_handleMutexes[i]);
std::lock_guard<wpi::mutex> handleLock(m_handleMutexes[i]);
m_structures[i].reset();
}
}

View File

@@ -55,12 +55,12 @@ 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<wpi::mutex> sync(m_allocateMutex);
std::lock_guard<wpi::mutex> lock(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<wpi::mutex> sync(m_handleMutexes[i]);
std::lock_guard<wpi::mutex> lock(m_handleMutexes[i]);
m_structures[i] = std::make_shared<TStruct>();
return static_cast<THandle>(createHandle(i, enumValue, m_version));
}
@@ -77,7 +77,7 @@ LimitedHandleResource<THandle, TStruct, size, enumValue>::Get(THandle handle) {
if (index < 0 || index >= size) {
return nullptr;
}
std::lock_guard<wpi::mutex> sync(m_handleMutexes[index]);
std::lock_guard<wpi::mutex> lock(m_handleMutexes[index]);
// return structure. Null will propogate correctly, so no need to manually
// check.
return m_structures[index];
@@ -91,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<wpi::mutex> sync(m_allocateMutex);
std::lock_guard<wpi::mutex> lock(m_handleMutexes[index]);
std::lock_guard<wpi::mutex> allocateLock(m_allocateMutex);
std::lock_guard<wpi::mutex> handleLock(m_handleMutexes[index]);
m_structures[index].reset();
}
@@ -100,9 +100,9 @@ template <typename THandle, typename TStruct, int16_t size,
HAL_HandleEnum enumValue>
void LimitedHandleResource<THandle, TStruct, size, enumValue>::ResetHandles() {
{
std::lock_guard<wpi::mutex> lock(m_allocateMutex);
std::lock_guard<wpi::mutex> allocateLock(m_allocateMutex);
for (int i = 0; i < size; i++) {
std::lock_guard<wpi::mutex> sync(m_handleMutexes[i]);
std::lock_guard<wpi::mutex> handleLock(m_handleMutexes[i]);
m_structures[i].reset();
}
}

View File

@@ -63,7 +63,7 @@ class UnlimitedHandleResource : public HandleBase {
template <typename THandle, typename TStruct, HAL_HandleEnum enumValue>
THandle UnlimitedHandleResource<THandle, TStruct, enumValue>::Allocate(
std::shared_ptr<TStruct> structure) {
std::lock_guard<wpi::mutex> sync(m_handleMutex);
std::lock_guard<wpi::mutex> lock(m_handleMutex);
size_t i;
for (i = 0; i < m_structures.size(); i++) {
if (m_structures[i] == nullptr) {
@@ -82,7 +82,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<wpi::mutex> sync(m_handleMutex);
std::lock_guard<wpi::mutex> lock(m_handleMutex);
if (index < 0 || index >= static_cast<int16_t>(m_structures.size()))
return nullptr;
return m_structures[index];
@@ -92,7 +92,7 @@ template <typename THandle, typename TStruct, HAL_HandleEnum enumValue>
std::shared_ptr<TStruct>
UnlimitedHandleResource<THandle, TStruct, enumValue>::Free(THandle handle) {
int16_t index = getHandleTypedIndex(handle, enumValue, m_version);
std::lock_guard<wpi::mutex> sync(m_handleMutex);
std::lock_guard<wpi::mutex> lock(m_handleMutex);
if (index < 0 || index >= static_cast<int16_t>(m_structures.size()))
return nullptr;
return std::move(m_structures[index]);
@@ -113,7 +113,7 @@ template <typename THandle, typename TStruct, HAL_HandleEnum enumValue>
template <typename Functor>
void UnlimitedHandleResource<THandle, TStruct, enumValue>::ForEach(
Functor func) {
std::lock_guard<wpi::mutex> sync(m_handleMutex);
std::lock_guard<wpi::mutex> lock(m_handleMutex);
size_t i;
for (i = 0; i < m_structures.size(); i++) {
if (m_structures[i] != nullptr) {

View File

@@ -40,7 +40,7 @@ void Scheduler::SetEnabled(bool enabled) { m_enabled = enabled; }
* @param command The command to be scheduled
*/
void Scheduler::AddCommand(Command* command) {
std::lock_guard<wpi::mutex> sync(m_additionsLock);
std::lock_guard<wpi::mutex> lock(m_additionsMutex);
if (std::find(m_additions.begin(), m_additions.end(), command) !=
m_additions.end())
return;
@@ -48,7 +48,7 @@ void Scheduler::AddCommand(Command* command) {
}
void Scheduler::AddButton(ButtonScheduler* button) {
std::lock_guard<wpi::mutex> sync(m_buttonsLock);
std::lock_guard<wpi::mutex> lock(m_buttonsMutex);
m_buttons.push_back(button);
}
@@ -114,7 +114,7 @@ void Scheduler::Run() {
{
if (!m_enabled) return;
std::lock_guard<wpi::mutex> sync(m_buttonsLock);
std::lock_guard<wpi::mutex> lock(m_buttonsMutex);
for (auto rButtonIter = m_buttons.rbegin(); rButtonIter != m_buttons.rend();
rButtonIter++) {
(*rButtonIter)->Execute();
@@ -144,7 +144,7 @@ void Scheduler::Run() {
// Add the new things
{
std::lock_guard<wpi::mutex> sync(m_additionsLock);
std::lock_guard<wpi::mutex> lock(m_additionsMutex);
for (auto additionsIter = m_additions.begin();
additionsIter != m_additions.end(); additionsIter++) {
ProcessCommandAddition(*additionsIter);

View File

@@ -26,7 +26,7 @@ std::array<bool, 3> DigitalGlitchFilter::m_filterAllocated = {
wpi::mutex DigitalGlitchFilter::m_mutex;
DigitalGlitchFilter::DigitalGlitchFilter() {
std::lock_guard<wpi::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> lock(m_mutex);
auto index =
std::find(m_filterAllocated.begin(), m_filterAllocated.end(), false);
wpi_assert(index != m_filterAllocated.end());
@@ -39,7 +39,7 @@ DigitalGlitchFilter::DigitalGlitchFilter() {
DigitalGlitchFilter::~DigitalGlitchFilter() {
if (m_channelIndex >= 0) {
std::lock_guard<wpi::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> lock(m_mutex);
m_filterAllocated[m_channelIndex] = false;
}
}

View File

@@ -38,12 +38,12 @@ MotorSafetyHelper::MotorSafetyHelper(MotorSafety* safeObject)
m_expiration = DEFAULT_SAFETY_EXPIRATION;
m_stopTime = Timer::GetFPGATimestamp();
std::lock_guard<wpi::mutex> sync(m_listMutex);
std::lock_guard<wpi::mutex> lock(m_listMutex);
m_helperList.insert(this);
}
MotorSafetyHelper::~MotorSafetyHelper() {
std::lock_guard<wpi::mutex> sync(m_listMutex);
std::lock_guard<wpi::mutex> lock(m_listMutex);
m_helperList.erase(this);
}
@@ -53,7 +53,7 @@ MotorSafetyHelper::~MotorSafetyHelper() {
* Resets the timer on this object that is used to do the timeouts.
*/
void MotorSafetyHelper::Feed() {
std::lock_guard<wpi::mutex> sync(m_syncMutex);
std::lock_guard<wpi::mutex> lock(m_thisMutex);
m_stopTime = Timer::GetFPGATimestamp() + m_expiration;
}
@@ -63,7 +63,7 @@ void MotorSafetyHelper::Feed() {
* @param expirationTime The timeout value in seconds.
*/
void MotorSafetyHelper::SetExpiration(double expirationTime) {
std::lock_guard<wpi::mutex> sync(m_syncMutex);
std::lock_guard<wpi::mutex> lock(m_thisMutex);
m_expiration = expirationTime;
}
@@ -73,7 +73,7 @@ void MotorSafetyHelper::SetExpiration(double expirationTime) {
* @return the timeout value in seconds.
*/
double MotorSafetyHelper::GetExpiration() const {
std::lock_guard<wpi::mutex> sync(m_syncMutex);
std::lock_guard<wpi::mutex> lock(m_thisMutex);
return m_expiration;
}
@@ -84,7 +84,7 @@ double MotorSafetyHelper::GetExpiration() const {
* timed out.
*/
bool MotorSafetyHelper::IsAlive() const {
std::lock_guard<wpi::mutex> sync(m_syncMutex);
std::lock_guard<wpi::mutex> lock(m_thisMutex);
return !m_enabled || m_stopTime > Timer::GetFPGATimestamp();
}
@@ -99,7 +99,7 @@ void MotorSafetyHelper::Check() {
DriverStation& ds = DriverStation::GetInstance();
if (!m_enabled || ds.IsDisabled() || ds.IsTest()) return;
std::lock_guard<wpi::mutex> sync(m_syncMutex);
std::lock_guard<wpi::mutex> lock(m_thisMutex);
if (m_stopTime < Timer::GetFPGATimestamp()) {
llvm::SmallString<128> buf;
llvm::raw_svector_ostream desc(buf);
@@ -118,7 +118,7 @@ void MotorSafetyHelper::Check() {
* @param enabled True if motor safety is enforced for this object
*/
void MotorSafetyHelper::SetSafetyEnabled(bool enabled) {
std::lock_guard<wpi::mutex> sync(m_syncMutex);
std::lock_guard<wpi::mutex> lock(m_thisMutex);
m_enabled = enabled;
}
@@ -130,7 +130,7 @@ void MotorSafetyHelper::SetSafetyEnabled(bool enabled) {
* @return True if motor safety is enforced for this device
*/
bool MotorSafetyHelper::IsSafetyEnabled() const {
std::lock_guard<wpi::mutex> sync(m_syncMutex);
std::lock_guard<wpi::mutex> lock(m_thisMutex);
return m_enabled;
}
@@ -141,7 +141,7 @@ bool MotorSafetyHelper::IsSafetyEnabled() const {
* that have timed out.
*/
void MotorSafetyHelper::CheckMotors() {
std::lock_guard<wpi::mutex> sync(m_listMutex);
std::lock_guard<wpi::mutex> lock(m_listMutex);
for (auto elem : m_helperList) {
elem->Check();
}

View File

@@ -39,7 +39,7 @@ Notifier::Notifier(TimerEventHandler handler) {
TimerEventHandler handler;
{
std::lock_guard<wpi::mutex> sync(m_processMutex);
std::lock_guard<wpi::mutex> lock(m_processMutex);
handler = m_handler;
if (m_periodic) {
m_expirationTime += m_period;
@@ -88,7 +88,7 @@ void Notifier::UpdateAlarm() {
* @param handler Handler
*/
void Notifier::SetHandler(TimerEventHandler handler) {
std::lock_guard<wpi::mutex> sync(m_processMutex);
std::lock_guard<wpi::mutex> lock(m_processMutex);
m_handler = handler;
}
@@ -100,7 +100,7 @@ void Notifier::SetHandler(TimerEventHandler handler) {
* @param delay Seconds to wait before the handler is called.
*/
void Notifier::StartSingle(double delay) {
std::lock_guard<wpi::mutex> sync(m_processMutex);
std::lock_guard<wpi::mutex> lock(m_processMutex);
m_periodic = false;
m_period = delay;
m_expirationTime = GetClock() + m_period;
@@ -118,7 +118,7 @@ void Notifier::StartSingle(double delay) {
* after the call to this method.
*/
void Notifier::StartPeriodic(double period) {
std::lock_guard<wpi::mutex> sync(m_processMutex);
std::lock_guard<wpi::mutex> lock(m_processMutex);
m_periodic = true;
m_period = period;
m_expirationTime = GetClock() + m_period;

View File

@@ -136,7 +136,7 @@ void PIDController::Calculate() {
PIDOutput* pidOutput;
{
std::lock_guard<wpi::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> lock(m_mutex);
pidInput = m_pidInput;
pidOutput = m_pidOutput;
enabled = m_enabled;
@@ -148,7 +148,7 @@ void PIDController::Calculate() {
if (enabled) {
double feedForward = CalculateFeedForward();
std::lock_guard<wpi::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> lock(m_mutex);
double input = pidInput->PIDGet();
double result;
PIDOutput* pidOutput;
@@ -219,7 +219,7 @@ double PIDController::CalculateFeedForward() {
*/
void PIDController::SetPID(double p, double i, double d) {
{
std::lock_guard<wpi::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> lock(m_mutex);
m_P = p;
m_I = i;
m_D = d;
@@ -242,7 +242,7 @@ void PIDController::SetPID(double p, double i, double d) {
*/
void PIDController::SetPID(double p, double i, double d, double f) {
{
std::lock_guard<wpi::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> lock(m_mutex);
m_P = p;
m_I = i;
m_D = d;
@@ -261,7 +261,7 @@ void PIDController::SetPID(double p, double i, double d, double f) {
* @return proportional coefficient
*/
double PIDController::GetP() const {
std::lock_guard<wpi::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> lock(m_mutex);
return m_P;
}
@@ -271,7 +271,7 @@ double PIDController::GetP() const {
* @return integral coefficient
*/
double PIDController::GetI() const {
std::lock_guard<wpi::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> lock(m_mutex);
return m_I;
}
@@ -281,7 +281,7 @@ double PIDController::GetI() const {
* @return differential coefficient
*/
double PIDController::GetD() const {
std::lock_guard<wpi::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> lock(m_mutex);
return m_D;
}
@@ -291,7 +291,7 @@ double PIDController::GetD() const {
* @return Feed forward coefficient
*/
double PIDController::GetF() const {
std::lock_guard<wpi::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> lock(m_mutex);
return m_F;
}
@@ -303,7 +303,7 @@ double PIDController::GetF() const {
* @return the latest calculated output
*/
double PIDController::Get() const {
std::lock_guard<wpi::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> lock(m_mutex);
return m_result;
}
@@ -317,7 +317,7 @@ double PIDController::Get() const {
* @param continuous true turns on continuous, false turns off continuous
*/
void PIDController::SetContinuous(bool continuous) {
std::lock_guard<wpi::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> lock(m_mutex);
m_continuous = continuous;
}
@@ -329,7 +329,7 @@ void PIDController::SetContinuous(bool continuous) {
*/
void PIDController::SetInputRange(double minimumInput, double maximumInput) {
{
std::lock_guard<wpi::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> lock(m_mutex);
m_minimumInput = minimumInput;
m_maximumInput = maximumInput;
}
@@ -344,7 +344,7 @@ void PIDController::SetInputRange(double minimumInput, double maximumInput) {
* @param maximumOutput the maximum value to write to the output
*/
void PIDController::SetOutputRange(double minimumOutput, double maximumOutput) {
std::lock_guard<wpi::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> lock(m_mutex);
m_minimumOutput = minimumOutput;
m_maximumOutput = maximumOutput;
}
@@ -356,7 +356,7 @@ void PIDController::SetOutputRange(double minimumOutput, double maximumOutput) {
*/
void PIDController::SetSetpoint(double setpoint) {
{
std::lock_guard<wpi::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> lock(m_mutex);
if (m_maximumInput > m_minimumInput) {
if (setpoint > m_maximumInput)
@@ -379,7 +379,7 @@ void PIDController::SetSetpoint(double setpoint) {
* @return the current setpoint
*/
double PIDController::GetSetpoint() const {
std::lock_guard<wpi::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> lock(m_mutex);
return m_setpoint;
}
@@ -389,7 +389,7 @@ double PIDController::GetSetpoint() const {
* @return the change in setpoint over time
*/
double PIDController::GetDeltaSetpoint() const {
std::lock_guard<wpi::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> lock(m_mutex);
return (m_setpoint - m_prevSetpoint) / m_setpointTimer.Get();
}
@@ -401,7 +401,7 @@ double PIDController::GetDeltaSetpoint() const {
double PIDController::GetError() const {
double setpoint = GetSetpoint();
{
std::lock_guard<wpi::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> lock(m_mutex);
return GetContinuousError(setpoint - m_pidInput->PIDGet());
}
}
@@ -438,7 +438,7 @@ PIDSourceType PIDController::GetPIDSourceType() const {
* @param percentage error which is tolerable
*/
void PIDController::SetTolerance(double percent) {
std::lock_guard<wpi::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> lock(m_mutex);
m_toleranceType = kPercentTolerance;
m_tolerance = percent;
}
@@ -450,7 +450,7 @@ void PIDController::SetTolerance(double percent) {
* @param percentage error which is tolerable
*/
void PIDController::SetAbsoluteTolerance(double absTolerance) {
std::lock_guard<wpi::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> lock(m_mutex);
m_toleranceType = kAbsoluteTolerance;
m_tolerance = absTolerance;
}
@@ -462,7 +462,7 @@ void PIDController::SetAbsoluteTolerance(double absTolerance) {
* @param percentage error which is tolerable
*/
void PIDController::SetPercentTolerance(double percent) {
std::lock_guard<wpi::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> lock(m_mutex);
m_toleranceType = kPercentTolerance;
m_tolerance = percent;
}
@@ -478,7 +478,7 @@ void PIDController::SetPercentTolerance(double percent) {
* @param bufLength Number of previous cycles to average. Defaults to 1.
*/
void PIDController::SetToleranceBuffer(int bufLength) {
std::lock_guard<wpi::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> lock(m_mutex);
// Create LinearDigitalFilter with original source as its source argument
m_filter = LinearDigitalFilter::MovingAverage(m_origSource, bufLength);
@@ -499,7 +499,7 @@ void PIDController::SetToleranceBuffer(int bufLength) {
bool PIDController::OnTarget() const {
double error = GetError();
std::lock_guard<wpi::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> lock(m_mutex);
switch (m_toleranceType) {
case kPercentTolerance:
return std::fabs(error) <
@@ -520,7 +520,7 @@ bool PIDController::OnTarget() const {
*/
void PIDController::Enable() {
{
std::lock_guard<wpi::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> lock(m_mutex);
m_enabled = true;
}
@@ -532,7 +532,7 @@ void PIDController::Enable() {
*/
void PIDController::Disable() {
{
std::lock_guard<wpi::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> lock(m_mutex);
m_pidOutput->PIDWrite(0);
m_enabled = false;
}
@@ -544,7 +544,7 @@ void PIDController::Disable() {
* Return true if PIDController is enabled.
*/
bool PIDController::IsEnabled() const {
std::lock_guard<wpi::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> lock(m_mutex);
return m_enabled;
}
@@ -554,7 +554,7 @@ bool PIDController::IsEnabled() const {
void PIDController::Reset() {
Disable();
std::lock_guard<wpi::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> lock(m_mutex);
m_prevError = 0;
m_totalError = 0;
m_result = 0;
@@ -583,7 +583,7 @@ void PIDController::InitTable(std::shared_ptr<nt::NetworkTable> subtable) {
m_pListener = m_pEntry.AddListener(
[=](const nt::EntryNotification& event) {
if (!event.value->IsDouble()) return;
std::lock_guard<wpi::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> lock(m_mutex);
m_P = event.value->GetDouble();
},
NT_NOTIFY_NEW | NT_NOTIFY_UPDATE);
@@ -591,7 +591,7 @@ void PIDController::InitTable(std::shared_ptr<nt::NetworkTable> subtable) {
m_iListener = m_iEntry.AddListener(
[=](const nt::EntryNotification& event) {
if (!event.value->IsDouble()) return;
std::lock_guard<wpi::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> lock(m_mutex);
m_I = event.value->GetDouble();
},
NT_NOTIFY_NEW | NT_NOTIFY_UPDATE);
@@ -599,7 +599,7 @@ void PIDController::InitTable(std::shared_ptr<nt::NetworkTable> subtable) {
m_dListener = m_dEntry.AddListener(
[=](const nt::EntryNotification& event) {
if (!event.value->IsDouble()) return;
std::lock_guard<wpi::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> lock(m_mutex);
m_D = event.value->GetDouble();
},
NT_NOTIFY_NEW | NT_NOTIFY_UPDATE);
@@ -607,7 +607,7 @@ void PIDController::InitTable(std::shared_ptr<nt::NetworkTable> subtable) {
m_fListener = m_fEntry.AddListener(
[=](const nt::EntryNotification& event) {
if (!event.value->IsDouble()) return;
std::lock_guard<wpi::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> lock(m_mutex);
m_F = event.value->GetDouble();
},
NT_NOTIFY_NEW | NT_NOTIFY_UPDATE);

View File

@@ -38,7 +38,7 @@ Resource::Resource(uint32_t elements) {
*/
void Resource::CreateResourceObject(std::unique_ptr<Resource>& r,
uint32_t elements) {
std::lock_guard<wpi::mutex> sync(m_createMutex);
std::lock_guard<wpi::mutex> lock(m_createMutex);
if (!r) {
r = std::make_unique<Resource>(elements);
}
@@ -52,7 +52,7 @@ void Resource::CreateResourceObject(std::unique_ptr<Resource>& r,
* allocated.
*/
uint32_t Resource::Allocate(const std::string& resourceDesc) {
std::lock_guard<wpi::mutex> sync(m_allocateMutex);
std::lock_guard<wpi::mutex> lock(m_allocateMutex);
for (uint32_t i = 0; i < m_isAllocated.size(); i++) {
if (!m_isAllocated[i]) {
m_isAllocated[i] = true;
@@ -70,7 +70,7 @@ uint32_t Resource::Allocate(const std::string& resourceDesc) {
* verified unallocated, then returned.
*/
uint32_t Resource::Allocate(uint32_t index, const std::string& resourceDesc) {
std::lock_guard<wpi::mutex> sync(m_allocateMutex);
std::lock_guard<wpi::mutex> lock(m_allocateMutex);
if (index >= m_isAllocated.size()) {
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, resourceDesc);
return std::numeric_limits<uint32_t>::max();
@@ -91,7 +91,7 @@ uint32_t Resource::Allocate(uint32_t index, const std::string& resourceDesc) {
* be reused somewhere else in the program.
*/
void Resource::Free(uint32_t index) {
std::unique_lock<wpi::mutex> sync(m_allocateMutex);
std::unique_lock<wpi::mutex> lock(m_allocateMutex);
if (index == std::numeric_limits<uint32_t>::max()) return;
if (index >= m_isAllocated.size()) {
wpi_setWPIError(NotAllocated);

View File

@@ -80,7 +80,7 @@ double Timer::Get() const {
double result;
double currentTime = GetFPGATimestamp();
std::lock_guard<wpi::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> lock(m_mutex);
if (m_running) {
// If the current time is before the start time, then the FPGA clock rolled
// over. Compensate by adding the ~71 minutes that it takes to roll over to
@@ -104,7 +104,7 @@ double Timer::Get() const {
* now.
*/
void Timer::Reset() {
std::lock_guard<wpi::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> lock(m_mutex);
m_accumulatedTime = 0;
m_startTime = GetFPGATimestamp();
}
@@ -116,7 +116,7 @@ void Timer::Reset() {
* relative to the system clock.
*/
void Timer::Start() {
std::lock_guard<wpi::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> lock(m_mutex);
if (!m_running) {
m_startTime = GetFPGATimestamp();
m_running = true;
@@ -133,7 +133,7 @@ void Timer::Start() {
void Timer::Stop() {
double temp = Get();
std::lock_guard<wpi::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> lock(m_mutex);
if (m_running) {
m_accumulatedTime = temp;
m_running = false;
@@ -150,7 +150,7 @@ void Timer::Stop() {
*/
bool Timer::HasPeriodPassed(double period) {
if (Get() > period) {
std::lock_guard<wpi::mutex> sync(m_mutex);
std::lock_guard<wpi::mutex> lock(m_mutex);
// Advance the start time by the period.
m_startTime += period;
// Don't set it to the current time... we want to avoid drift.

View File

@@ -54,11 +54,11 @@ class Scheduler : public ErrorBase, public NamedSendable {
void ProcessCommandAddition(Command* command);
Command::SubsystemSet m_subsystems;
wpi::mutex m_buttonsLock;
wpi::mutex m_buttonsMutex;
typedef std::vector<ButtonScheduler*> ButtonVector;
ButtonVector m_buttons;
typedef std::vector<Command*> CommandVector;
wpi::mutex m_additionsLock;
wpi::mutex m_additionsMutex;
CommandVector m_additions;
typedef std::set<Command*> CommandSet;
CommandSet m_commands;

View File

@@ -41,7 +41,7 @@ class MotorSafetyHelper : public ErrorBase {
double m_stopTime;
// Protect accesses to the state for this object
mutable wpi::mutex m_syncMutex;
mutable wpi::mutex m_thisMutex;
// The object that is using the helper
MotorSafety* m_safeObject;