diff --git a/hal/src/main/native/athena/AnalogInput.cpp b/hal/src/main/native/athena/AnalogInput.cpp index cf302a1085..3153c8fbef 100644 --- a/hal/src/main/native/athena/AnalogInput.cpp +++ b/hal/src/main/native/athena/AnalogInput.cpp @@ -229,7 +229,7 @@ int32_t HAL_GetAnalogValue(HAL_AnalogInputHandle analogPortHandle, readSelect.Channel = port->channel; readSelect.Averaged = false; - std::lock_guard sync(analogRegisterWindowMutex); + std::lock_guard lock(analogRegisterWindowMutex); analogInputSystem->writeReadSelect(readSelect, status); analogInputSystem->strobeLatchOutput(status); return static_cast(analogInputSystem->readOutput(status)); @@ -260,7 +260,7 @@ int32_t HAL_GetAnalogAverageValue(HAL_AnalogInputHandle analogPortHandle, readSelect.Channel = port->channel; readSelect.Averaged = true; - std::lock_guard sync(analogRegisterWindowMutex); + std::lock_guard lock(analogRegisterWindowMutex); analogInputSystem->writeReadSelect(readSelect, status); analogInputSystem->strobeLatchOutput(status); return static_cast(analogInputSystem->readOutput(status)); diff --git a/hal/src/main/native/athena/AnalogInternal.cpp b/hal/src/main/native/athena/AnalogInternal.cpp index 64657c5f8d..182dd96556 100644 --- a/hal/src/main/native/athena/AnalogInternal.cpp +++ b/hal/src/main/native/athena/AnalogInternal.cpp @@ -36,7 +36,7 @@ bool analogSampleRateSet = false; */ void initializeAnalog(int32_t* status) { if (analogSystemInitialized) return; - std::lock_guard sync(analogRegisterWindowMutex); + std::lock_guard lock(analogRegisterWindowMutex); if (analogSystemInitialized) return; analogInputSystem.reset(tAI::create(status)); analogOutputSystem.reset(tAO::create(status)); diff --git a/hal/src/main/native/athena/DIO.cpp b/hal/src/main/native/athena/DIO.cpp index 9c7f92347b..2c97b0d14c 100644 --- a/hal/src/main/native/athena/DIO.cpp +++ b/hal/src/main/native/athena/DIO.cpp @@ -54,7 +54,7 @@ HAL_DigitalHandle HAL_InitializeDIOPort(HAL_PortHandle portHandle, port->channel = static_cast(channel); - std::lock_guard sync(digitalDIOMutex); + std::lock_guard 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 sync(digitalDIOMutex); + std::lock_guard 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 sync(digitalPwmMutex); + std::lock_guard 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 sync(digitalDIOMutex); + std::lock_guard 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 sync(digitalDIOMutex); + std::lock_guard 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 sync(digitalDIOMutex); + std::lock_guard 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 sync(digitalDIOMutex); + std::lock_guard 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 sync(digitalDIOMutex); + std::lock_guard lock(digitalDIOMutex); hdrPeriod = digitalSystem->readFilterPeriodHdr(filterIndex, status); if (*status == 0) { mxpPeriod = digitalSystem->readFilterPeriodMXP(filterIndex, status); diff --git a/hal/src/main/native/athena/I2C.cpp b/hal/src/main/native/athena/I2C.cpp index 9151105f39..932ccb8890 100644 --- a/hal/src/main/native/athena/I2C.cpp +++ b/hal/src/main/native/athena/I2C.cpp @@ -49,7 +49,7 @@ void HAL_InitializeI2C(HAL_I2CPort port, int32_t* status) { } if (port == 0) { - std::lock_guard sync(digitalI2COnBoardMutex); + std::lock_guard 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 sync(digitalI2CMXPMutex); + std::lock_guard 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 sync(digitalI2COnBoardMutex); + std::lock_guard lock(digitalI2COnBoardMutex); return ioctl(i2COnBoardHandle, I2C_RDWR, &rdwr); } else { - std::lock_guard sync(digitalI2CMXPMutex); + std::lock_guard 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 sync(digitalI2COnBoardMutex); + std::lock_guard lock(digitalI2COnBoardMutex); return ioctl(i2COnBoardHandle, I2C_RDWR, &rdwr); } else { - std::lock_guard sync(digitalI2CMXPMutex); + std::lock_guard 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 sync(digitalI2COnBoardMutex); + std::lock_guard lock(digitalI2COnBoardMutex); return ioctl(i2COnBoardHandle, I2C_RDWR, &rdwr); } else { - std::lock_guard sync(digitalI2CMXPMutex); + std::lock_guard lock(digitalI2CMXPMutex); return ioctl(i2CMXPHandle, I2C_RDWR, &rdwr); } } @@ -208,12 +208,12 @@ void HAL_CloseI2C(HAL_I2CPort port) { } if (port == 0) { - std::lock_guard sync(digitalI2COnBoardMutex); + std::lock_guard lock(digitalI2COnBoardMutex); if (i2COnboardObjCount-- == 0) { close(i2COnBoardHandle); } } else { - std::lock_guard sync(digitalI2CMXPMutex); + std::lock_guard lock(digitalI2CMXPMutex); if (i2CMXPObjCount-- == 0) { close(i2CMXPHandle); } diff --git a/hal/src/main/native/athena/Notifier.cpp b/hal/src/main/native/athena/Notifier.cpp index 7d48f78da7..ccff28851b 100644 --- a/hal/src/main/native/athena/Notifier.cpp +++ b/hal/src/main/native/athena/Notifier.cpp @@ -66,7 +66,7 @@ class NotifierHandleContainer static NotifierHandleContainer notifierHandles; static void alarmCallback(uint32_t, void*) { - std::lock_guard sync(notifierMutex); + std::lock_guard 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 sync(notifierMutex); + std::lock_guard lock(notifierMutex); // create manager and alarm if not already created if (!notifierManager) { notifierManager = std::make_unique( @@ -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 sync(notifierMutex); + std::lock_guard 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 sync(notifierMutex); + std::lock_guard lock(notifierMutex); // Update alarm time if closer than current. if (triggerTime < closestTrigger) { bool wasActive = (closestTrigger != UINT64_MAX); diff --git a/hal/src/main/native/athena/Relay.cpp b/hal/src/main/native/athena/Relay.cpp index 688a574bfa..0e33f9d623 100644 --- a/hal/src/main/native/athena/Relay.cpp +++ b/hal/src/main/native/athena/Relay.cpp @@ -92,7 +92,7 @@ void HAL_SetRelay(HAL_RelayHandle relayPortHandle, HAL_Bool on, *status = HAL_HANDLE_ERROR; return; } - std::lock_guard sync(digitalRelayMutex); + std::lock_guard lock(digitalRelayMutex); uint8_t relays = 0; if (port->fwd) { relays = relaySystem->readValue_Forward(status); diff --git a/hal/src/main/native/athena/SPI.cpp b/hal/src/main/native/athena/SPI.cpp index de86e66d5e..1f370bc5fe 100644 --- a/hal/src/main/native/athena/SPI.cpp +++ b/hal/src/main/native/athena/SPI.cpp @@ -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 sync(spiApiMutexes[port]); + std::lock_guard 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 sync(spiApiMutexes[port]); + std::lock_guard 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 sync(spiApiMutexes[port]); + std::lock_guard 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 sync(spiApiMutexes[port]); + std::lock_guard lock(spiApiMutexes[port]); close(HAL_GetSPIHandle(port)); } @@ -385,7 +385,7 @@ void HAL_SetSPISpeed(HAL_SPIPort port, int32_t speed) { return; } - std::lock_guard sync(spiApiMutexes[port]); + std::lock_guard 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 sync(spiApiMutexes[port]); + std::lock_guard 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 sync(spiApiMutexes[port]); + std::lock_guard 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 sync(spiApiMutexes[port]); + std::lock_guard 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 sync(spiHandleMutexes[port]); + std::lock_guard 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 sync(spiHandleMutexes[port]); + std::lock_guard 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 sync(spiAccumulatorMutexes[port]); + std::lock_guard lock(spiAccumulatorMutexes[port]); if (!spiAccumulators[port]) spiAccumulators[port] = std::make_unique(); SPIAccumulator* accum = spiAccumulators[port].get(); @@ -643,7 +643,7 @@ void HAL_FreeSPIAccumulator(HAL_SPIPort port, int32_t* status) { return; } - std::lock_guard sync(spiAccumulatorMutexes[port]); + std::lock_guard 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 sync(spiApiMutexes[port]); + std::lock_guard 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 sync(spiAccumulatorMutexes[port]); + std::lock_guard 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 sync(spiAccumulatorMutexes[port]); + std::lock_guard 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 sync(spiAccumulatorMutexes[port]); + std::lock_guard 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 sync(spiAccumulatorMutexes[port]); + std::lock_guard 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 sync(spiAccumulatorMutexes[port]); + std::lock_guard 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 sync(spiAccumulatorMutexes[port]); + std::lock_guard lock(spiAccumulatorMutexes[port]); SPIAccumulator* accum = spiAccumulators[port].get(); if (!accum) { *status = NULL_PARAMETER; diff --git a/hal/src/main/native/include/HAL/handles/DigitalHandleResource.h b/hal/src/main/native/include/HAL/handles/DigitalHandleResource.h index f5f7dc0751..c472c9e269 100644 --- a/hal/src/main/native/include/HAL/handles/DigitalHandleResource.h +++ b/hal/src/main/native/include/HAL/handles/DigitalHandleResource.h @@ -60,7 +60,7 @@ THandle DigitalHandleResource::Allocate( *status = RESOURCE_OUT_OF_RANGE; return HAL_kInvalidHandle; } - std::lock_guard sync(m_handleMutexes[index]); + std::lock_guard 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 DigitalHandleResource::Get( if (index < 0 || index >= size) { return nullptr; } - std::lock_guard sync(m_handleMutexes[index]); + std::lock_guard 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::Free( int16_t index = getHandleTypedIndex(handle, enumValue, m_version); if (index < 0 || index >= size) return; // lock and deallocated handle - std::lock_guard sync(m_handleMutexes[index]); + std::lock_guard lock(m_handleMutexes[index]); m_structures[index].reset(); } template void DigitalHandleResource::ResetHandles() { for (int i = 0; i < size; i++) { - std::lock_guard sync(m_handleMutexes[i]); + std::lock_guard lock(m_handleMutexes[i]); m_structures[i].reset(); } HandleBase::ResetHandles(); diff --git a/hal/src/main/native/include/HAL/handles/IndexedClassedHandleResource.h b/hal/src/main/native/include/HAL/handles/IndexedClassedHandleResource.h index 7e91544ea3..48d3db6c91 100644 --- a/hal/src/main/native/include/HAL/handles/IndexedClassedHandleResource.h +++ b/hal/src/main/native/include/HAL/handles/IndexedClassedHandleResource.h @@ -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::Allocate( *status = RESOURCE_OUT_OF_RANGE; return HAL_kInvalidHandle; } - std::lock_guard sync(m_handleMutexes[index]); + std::lock_guard 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::Get( if (index < 0 || index >= size) { return nullptr; } - std::lock_guard sync(m_handleMutexes[index]); + std::lock_guard 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::Free( int16_t index = getHandleTypedIndex(handle, enumValue, m_version); if (index < 0 || index >= size) return; // lock and deallocated handle - std::lock_guard sync(m_handleMutexes[index]); + std::lock_guard lock(m_handleMutexes[index]); m_structures[index].reset(); } @@ -117,7 +116,7 @@ template ::ResetHandles() { for (int i = 0; i < size; i++) { - std::lock_guard sync(m_handleMutexes[i]); + std::lock_guard lock(m_handleMutexes[i]); m_structures[i].reset(); } HandleBase::ResetHandles(); diff --git a/hal/src/main/native/include/HAL/handles/IndexedHandleResource.h b/hal/src/main/native/include/HAL/handles/IndexedHandleResource.h index 5d9852dc21..1dd41baf0b 100644 --- a/hal/src/main/native/include/HAL/handles/IndexedHandleResource.h +++ b/hal/src/main/native/include/HAL/handles/IndexedHandleResource.h @@ -62,7 +62,7 @@ THandle IndexedHandleResource::Allocate( *status = RESOURCE_OUT_OF_RANGE; return HAL_kInvalidHandle; } - std::lock_guard sync(m_handleMutexes[index]); + std::lock_guard 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::Get(THandle handle) { if (index < 0 || index >= size) { return nullptr; } - std::lock_guard sync(m_handleMutexes[index]); + std::lock_guard 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::Free( int16_t index = getHandleTypedIndex(handle, enumValue, m_version); if (index < 0 || index >= size) return; // lock and deallocated handle - std::lock_guard sync(m_handleMutexes[index]); + std::lock_guard lock(m_handleMutexes[index]); m_structures[index].reset(); } @@ -103,7 +103,7 @@ template void IndexedHandleResource::ResetHandles() { for (int i = 0; i < size; i++) { - std::lock_guard sync(m_handleMutexes[i]); + std::lock_guard lock(m_handleMutexes[i]); m_structures[i].reset(); } HandleBase::ResetHandles(); diff --git a/hal/src/main/native/include/HAL/handles/LimitedClassedHandleResource.h b/hal/src/main/native/include/HAL/handles/LimitedClassedHandleResource.h index 513870b6f6..264d3963d2 100644 --- a/hal/src/main/native/include/HAL/handles/LimitedClassedHandleResource.h +++ b/hal/src/main/native/include/HAL/handles/LimitedClassedHandleResource.h @@ -59,12 +59,12 @@ THandle LimitedClassedHandleResource::Allocate( std::shared_ptr toSet) { // globally lock to loop through indices - std::lock_guard sync(m_allocateMutex); + std::lock_guard 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 sync(m_handleMutexes[i]); + std::lock_guard lock(m_handleMutexes[i]); m_structures[i] = toSet; return static_cast(createHandle(i, enumValue, m_version)); } @@ -82,7 +82,7 @@ LimitedClassedHandleResource::Get( if (index < 0 || index >= size) { return nullptr; } - std::lock_guard sync(m_handleMutexes[index]); + std::lock_guard 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::Free( int16_t index = getHandleTypedIndex(handle, enumValue, m_version); if (index < 0 || index >= size) return; // lock and deallocated handle - std::lock_guard sync(m_allocateMutex); - std::lock_guard lock(m_handleMutexes[index]); + std::lock_guard allocateLock(m_allocateMutex); + std::lock_guard handleLock(m_handleMutexes[index]); m_structures[index].reset(); } @@ -106,9 +106,9 @@ template ::ResetHandles() { { - std::lock_guard lock(m_allocateMutex); + std::lock_guard allocateLock(m_allocateMutex); for (int i = 0; i < size; i++) { - std::lock_guard sync(m_handleMutexes[i]); + std::lock_guard handleLock(m_handleMutexes[i]); m_structures[i].reset(); } } diff --git a/hal/src/main/native/include/HAL/handles/LimitedHandleResource.h b/hal/src/main/native/include/HAL/handles/LimitedHandleResource.h index 2f1ffab73f..0caf71144b 100644 --- a/hal/src/main/native/include/HAL/handles/LimitedHandleResource.h +++ b/hal/src/main/native/include/HAL/handles/LimitedHandleResource.h @@ -55,12 +55,12 @@ template THandle LimitedHandleResource::Allocate() { // globally lock to loop through indices - std::lock_guard sync(m_allocateMutex); + std::lock_guard 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 sync(m_handleMutexes[i]); + std::lock_guard lock(m_handleMutexes[i]); m_structures[i] = std::make_shared(); return static_cast(createHandle(i, enumValue, m_version)); } @@ -77,7 +77,7 @@ LimitedHandleResource::Get(THandle handle) { if (index < 0 || index >= size) { return nullptr; } - std::lock_guard sync(m_handleMutexes[index]); + std::lock_guard 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::Free( int16_t index = getHandleTypedIndex(handle, enumValue, m_version); if (index < 0 || index >= size) return; // lock and deallocated handle - std::lock_guard sync(m_allocateMutex); - std::lock_guard lock(m_handleMutexes[index]); + std::lock_guard allocateLock(m_allocateMutex); + std::lock_guard handleLock(m_handleMutexes[index]); m_structures[index].reset(); } @@ -100,9 +100,9 @@ template void LimitedHandleResource::ResetHandles() { { - std::lock_guard lock(m_allocateMutex); + std::lock_guard allocateLock(m_allocateMutex); for (int i = 0; i < size; i++) { - std::lock_guard sync(m_handleMutexes[i]); + std::lock_guard handleLock(m_handleMutexes[i]); m_structures[i].reset(); } } diff --git a/hal/src/main/native/include/HAL/handles/UnlimitedHandleResource.h b/hal/src/main/native/include/HAL/handles/UnlimitedHandleResource.h index 0cff63956b..2fada08457 100644 --- a/hal/src/main/native/include/HAL/handles/UnlimitedHandleResource.h +++ b/hal/src/main/native/include/HAL/handles/UnlimitedHandleResource.h @@ -63,7 +63,7 @@ class UnlimitedHandleResource : public HandleBase { template THandle UnlimitedHandleResource::Allocate( std::shared_ptr structure) { - std::lock_guard sync(m_handleMutex); + std::lock_guard lock(m_handleMutex); size_t i; for (i = 0; i < m_structures.size(); i++) { if (m_structures[i] == nullptr) { @@ -82,7 +82,7 @@ template std::shared_ptr UnlimitedHandleResource::Get(THandle handle) { int16_t index = getHandleTypedIndex(handle, enumValue, m_version); - std::lock_guard sync(m_handleMutex); + std::lock_guard lock(m_handleMutex); if (index < 0 || index >= static_cast(m_structures.size())) return nullptr; return m_structures[index]; @@ -92,7 +92,7 @@ template std::shared_ptr UnlimitedHandleResource::Free(THandle handle) { int16_t index = getHandleTypedIndex(handle, enumValue, m_version); - std::lock_guard sync(m_handleMutex); + std::lock_guard lock(m_handleMutex); if (index < 0 || index >= static_cast(m_structures.size())) return nullptr; return std::move(m_structures[index]); @@ -113,7 +113,7 @@ template template void UnlimitedHandleResource::ForEach( Functor func) { - std::lock_guard sync(m_handleMutex); + std::lock_guard lock(m_handleMutex); size_t i; for (i = 0; i < m_structures.size(); i++) { if (m_structures[i] != nullptr) { diff --git a/wpilibc/src/main/native/cpp/Commands/Scheduler.cpp b/wpilibc/src/main/native/cpp/Commands/Scheduler.cpp index 2c840a7f57..a3d42dcfcf 100644 --- a/wpilibc/src/main/native/cpp/Commands/Scheduler.cpp +++ b/wpilibc/src/main/native/cpp/Commands/Scheduler.cpp @@ -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 sync(m_additionsLock); + std::lock_guard 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 sync(m_buttonsLock); + std::lock_guard lock(m_buttonsMutex); m_buttons.push_back(button); } @@ -114,7 +114,7 @@ void Scheduler::Run() { { if (!m_enabled) return; - std::lock_guard sync(m_buttonsLock); + std::lock_guard 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 sync(m_additionsLock); + std::lock_guard lock(m_additionsMutex); for (auto additionsIter = m_additions.begin(); additionsIter != m_additions.end(); additionsIter++) { ProcessCommandAddition(*additionsIter); diff --git a/wpilibc/src/main/native/cpp/DigitalGlitchFilter.cpp b/wpilibc/src/main/native/cpp/DigitalGlitchFilter.cpp index f42cf619e0..71cf59840c 100644 --- a/wpilibc/src/main/native/cpp/DigitalGlitchFilter.cpp +++ b/wpilibc/src/main/native/cpp/DigitalGlitchFilter.cpp @@ -26,7 +26,7 @@ std::array DigitalGlitchFilter::m_filterAllocated = { wpi::mutex DigitalGlitchFilter::m_mutex; DigitalGlitchFilter::DigitalGlitchFilter() { - std::lock_guard sync(m_mutex); + std::lock_guard 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 sync(m_mutex); + std::lock_guard lock(m_mutex); m_filterAllocated[m_channelIndex] = false; } } diff --git a/wpilibc/src/main/native/cpp/MotorSafetyHelper.cpp b/wpilibc/src/main/native/cpp/MotorSafetyHelper.cpp index 0b5a56fd91..fd237c2491 100644 --- a/wpilibc/src/main/native/cpp/MotorSafetyHelper.cpp +++ b/wpilibc/src/main/native/cpp/MotorSafetyHelper.cpp @@ -38,12 +38,12 @@ MotorSafetyHelper::MotorSafetyHelper(MotorSafety* safeObject) m_expiration = DEFAULT_SAFETY_EXPIRATION; m_stopTime = Timer::GetFPGATimestamp(); - std::lock_guard sync(m_listMutex); + std::lock_guard lock(m_listMutex); m_helperList.insert(this); } MotorSafetyHelper::~MotorSafetyHelper() { - std::lock_guard sync(m_listMutex); + std::lock_guard 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 sync(m_syncMutex); + std::lock_guard 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 sync(m_syncMutex); + std::lock_guard 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 sync(m_syncMutex); + std::lock_guard lock(m_thisMutex); return m_expiration; } @@ -84,7 +84,7 @@ double MotorSafetyHelper::GetExpiration() const { * timed out. */ bool MotorSafetyHelper::IsAlive() const { - std::lock_guard sync(m_syncMutex); + std::lock_guard 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 sync(m_syncMutex); + std::lock_guard 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 sync(m_syncMutex); + std::lock_guard 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 sync(m_syncMutex); + std::lock_guard lock(m_thisMutex); return m_enabled; } @@ -141,7 +141,7 @@ bool MotorSafetyHelper::IsSafetyEnabled() const { * that have timed out. */ void MotorSafetyHelper::CheckMotors() { - std::lock_guard sync(m_listMutex); + std::lock_guard lock(m_listMutex); for (auto elem : m_helperList) { elem->Check(); } diff --git a/wpilibc/src/main/native/cpp/Notifier.cpp b/wpilibc/src/main/native/cpp/Notifier.cpp index ec3a1b56ac..06dfb0d8b0 100644 --- a/wpilibc/src/main/native/cpp/Notifier.cpp +++ b/wpilibc/src/main/native/cpp/Notifier.cpp @@ -39,7 +39,7 @@ Notifier::Notifier(TimerEventHandler handler) { TimerEventHandler handler; { - std::lock_guard sync(m_processMutex); + std::lock_guard 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 sync(m_processMutex); + std::lock_guard 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 sync(m_processMutex); + std::lock_guard 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 sync(m_processMutex); + std::lock_guard lock(m_processMutex); m_periodic = true; m_period = period; m_expirationTime = GetClock() + m_period; diff --git a/wpilibc/src/main/native/cpp/PIDController.cpp b/wpilibc/src/main/native/cpp/PIDController.cpp index f613ebf7ad..0ce0058dd6 100644 --- a/wpilibc/src/main/native/cpp/PIDController.cpp +++ b/wpilibc/src/main/native/cpp/PIDController.cpp @@ -136,7 +136,7 @@ void PIDController::Calculate() { PIDOutput* pidOutput; { - std::lock_guard sync(m_mutex); + std::lock_guard 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 sync(m_mutex); + std::lock_guard 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 sync(m_mutex); + std::lock_guard 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 sync(m_mutex); + std::lock_guard 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 sync(m_mutex); + std::lock_guard lock(m_mutex); return m_P; } @@ -271,7 +271,7 @@ double PIDController::GetP() const { * @return integral coefficient */ double PIDController::GetI() const { - std::lock_guard sync(m_mutex); + std::lock_guard lock(m_mutex); return m_I; } @@ -281,7 +281,7 @@ double PIDController::GetI() const { * @return differential coefficient */ double PIDController::GetD() const { - std::lock_guard sync(m_mutex); + std::lock_guard 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 sync(m_mutex); + std::lock_guard 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 sync(m_mutex); + std::lock_guard 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 sync(m_mutex); + std::lock_guard 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 sync(m_mutex); + std::lock_guard 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 sync(m_mutex); + std::lock_guard 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 sync(m_mutex); + std::lock_guard 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 sync(m_mutex); + std::lock_guard 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 sync(m_mutex); + std::lock_guard 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 sync(m_mutex); + std::lock_guard 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 sync(m_mutex); + std::lock_guard 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 sync(m_mutex); + std::lock_guard 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 sync(m_mutex); + std::lock_guard 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 sync(m_mutex); + std::lock_guard 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 sync(m_mutex); + std::lock_guard 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 sync(m_mutex); + std::lock_guard lock(m_mutex); m_enabled = true; } @@ -532,7 +532,7 @@ void PIDController::Enable() { */ void PIDController::Disable() { { - std::lock_guard sync(m_mutex); + std::lock_guard 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 sync(m_mutex); + std::lock_guard lock(m_mutex); return m_enabled; } @@ -554,7 +554,7 @@ bool PIDController::IsEnabled() const { void PIDController::Reset() { Disable(); - std::lock_guard sync(m_mutex); + std::lock_guard lock(m_mutex); m_prevError = 0; m_totalError = 0; m_result = 0; @@ -583,7 +583,7 @@ void PIDController::InitTable(std::shared_ptr subtable) { m_pListener = m_pEntry.AddListener( [=](const nt::EntryNotification& event) { if (!event.value->IsDouble()) return; - std::lock_guard sync(m_mutex); + std::lock_guard lock(m_mutex); m_P = event.value->GetDouble(); }, NT_NOTIFY_NEW | NT_NOTIFY_UPDATE); @@ -591,7 +591,7 @@ void PIDController::InitTable(std::shared_ptr subtable) { m_iListener = m_iEntry.AddListener( [=](const nt::EntryNotification& event) { if (!event.value->IsDouble()) return; - std::lock_guard sync(m_mutex); + std::lock_guard lock(m_mutex); m_I = event.value->GetDouble(); }, NT_NOTIFY_NEW | NT_NOTIFY_UPDATE); @@ -599,7 +599,7 @@ void PIDController::InitTable(std::shared_ptr subtable) { m_dListener = m_dEntry.AddListener( [=](const nt::EntryNotification& event) { if (!event.value->IsDouble()) return; - std::lock_guard sync(m_mutex); + std::lock_guard lock(m_mutex); m_D = event.value->GetDouble(); }, NT_NOTIFY_NEW | NT_NOTIFY_UPDATE); @@ -607,7 +607,7 @@ void PIDController::InitTable(std::shared_ptr subtable) { m_fListener = m_fEntry.AddListener( [=](const nt::EntryNotification& event) { if (!event.value->IsDouble()) return; - std::lock_guard sync(m_mutex); + std::lock_guard lock(m_mutex); m_F = event.value->GetDouble(); }, NT_NOTIFY_NEW | NT_NOTIFY_UPDATE); diff --git a/wpilibc/src/main/native/cpp/Resource.cpp b/wpilibc/src/main/native/cpp/Resource.cpp index e266e6dabb..6f59990cb2 100644 --- a/wpilibc/src/main/native/cpp/Resource.cpp +++ b/wpilibc/src/main/native/cpp/Resource.cpp @@ -38,7 +38,7 @@ Resource::Resource(uint32_t elements) { */ void Resource::CreateResourceObject(std::unique_ptr& r, uint32_t elements) { - std::lock_guard sync(m_createMutex); + std::lock_guard lock(m_createMutex); if (!r) { r = std::make_unique(elements); } @@ -52,7 +52,7 @@ void Resource::CreateResourceObject(std::unique_ptr& r, * allocated. */ uint32_t Resource::Allocate(const std::string& resourceDesc) { - std::lock_guard sync(m_allocateMutex); + std::lock_guard 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 sync(m_allocateMutex); + std::lock_guard lock(m_allocateMutex); if (index >= m_isAllocated.size()) { wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, resourceDesc); return std::numeric_limits::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 sync(m_allocateMutex); + std::unique_lock lock(m_allocateMutex); if (index == std::numeric_limits::max()) return; if (index >= m_isAllocated.size()) { wpi_setWPIError(NotAllocated); diff --git a/wpilibc/src/main/native/cpp/Timer.cpp b/wpilibc/src/main/native/cpp/Timer.cpp index 98707dc9d7..2641f8a1a3 100644 --- a/wpilibc/src/main/native/cpp/Timer.cpp +++ b/wpilibc/src/main/native/cpp/Timer.cpp @@ -80,7 +80,7 @@ double Timer::Get() const { double result; double currentTime = GetFPGATimestamp(); - std::lock_guard sync(m_mutex); + std::lock_guard 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 sync(m_mutex); + std::lock_guard 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 sync(m_mutex); + std::lock_guard 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 sync(m_mutex); + std::lock_guard 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 sync(m_mutex); + std::lock_guard 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. diff --git a/wpilibc/src/main/native/include/Commands/Scheduler.h b/wpilibc/src/main/native/include/Commands/Scheduler.h index d821a06b9d..2c494cf5ed 100644 --- a/wpilibc/src/main/native/include/Commands/Scheduler.h +++ b/wpilibc/src/main/native/include/Commands/Scheduler.h @@ -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 ButtonVector; ButtonVector m_buttons; typedef std::vector CommandVector; - wpi::mutex m_additionsLock; + wpi::mutex m_additionsMutex; CommandVector m_additions; typedef std::set CommandSet; CommandSet m_commands; diff --git a/wpilibc/src/main/native/include/MotorSafetyHelper.h b/wpilibc/src/main/native/include/MotorSafetyHelper.h index acff7e6138..01929b9e36 100644 --- a/wpilibc/src/main/native/include/MotorSafetyHelper.h +++ b/wpilibc/src/main/native/include/MotorSafetyHelper.h @@ -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;