mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-27 02:01:42 +00:00
Remove template types from lock RAII wrapper usages (#1756)
C++17 has template type autodeduction. These wrappers include std::lock_guard and std::unique_lock.
This commit is contained in:
committed by
Peter Johnson
parent
e582518bae
commit
841ef5d739
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-2019 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. */
|
||||
@@ -149,7 +149,7 @@ int32_t HAL_GetAnalogValue(HAL_AnalogInputHandle analogPortHandle,
|
||||
readSelect.Channel = port->channel;
|
||||
readSelect.Averaged = false;
|
||||
|
||||
std::lock_guard<wpi::mutex> lock(analogRegisterWindowMutex);
|
||||
std::lock_guard lock(analogRegisterWindowMutex);
|
||||
analogInputSystem->writeReadSelect(readSelect, status);
|
||||
analogInputSystem->strobeLatchOutput(status);
|
||||
return static_cast<int16_t>(analogInputSystem->readOutput(status));
|
||||
@@ -166,7 +166,7 @@ int32_t HAL_GetAnalogAverageValue(HAL_AnalogInputHandle analogPortHandle,
|
||||
readSelect.Channel = port->channel;
|
||||
readSelect.Averaged = true;
|
||||
|
||||
std::lock_guard<wpi::mutex> lock(analogRegisterWindowMutex);
|
||||
std::lock_guard lock(analogRegisterWindowMutex);
|
||||
analogInputSystem->writeReadSelect(readSelect, status);
|
||||
analogInputSystem->strobeLatchOutput(status);
|
||||
return static_cast<int32_t>(analogInputSystem->readOutput(status));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-2019 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. */
|
||||
@@ -44,7 +44,7 @@ void InitializeAnalogInternal() {
|
||||
void initializeAnalog(int32_t* status) {
|
||||
hal::init::CheckInit();
|
||||
if (analogSystemInitialized) return;
|
||||
std::lock_guard<wpi::mutex> lock(analogRegisterWindowMutex);
|
||||
std::lock_guard lock(analogRegisterWindowMutex);
|
||||
if (analogSystemInitialized) return;
|
||||
analogInputSystem.reset(tAI::create(status));
|
||||
analogOutputSystem.reset(tAO::create(status));
|
||||
|
||||
@@ -91,7 +91,7 @@ HAL_CANHandle HAL_InitializeCAN(HAL_CANManufacturer manufacturer,
|
||||
void HAL_CleanCAN(HAL_CANHandle handle) {
|
||||
auto data = canHandles->Free(handle);
|
||||
|
||||
std::lock_guard<wpi::mutex> lock(data->mapMutex);
|
||||
std::lock_guard lock(data->mapMutex);
|
||||
|
||||
for (auto&& i : data->periodicSends) {
|
||||
int32_t s = 0;
|
||||
@@ -115,7 +115,7 @@ void HAL_WriteCANPacket(HAL_CANHandle handle, const uint8_t* data,
|
||||
if (*status != 0) {
|
||||
return;
|
||||
}
|
||||
std::lock_guard<wpi::mutex> lock(can->mapMutex);
|
||||
std::lock_guard lock(can->mapMutex);
|
||||
can->periodicSends[apiId] = -1;
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ void HAL_WriteCANPacketRepeating(HAL_CANHandle handle, const uint8_t* data,
|
||||
if (*status != 0) {
|
||||
return;
|
||||
}
|
||||
std::lock_guard<wpi::mutex> lock(can->mapMutex);
|
||||
std::lock_guard lock(can->mapMutex);
|
||||
can->periodicSends[apiId] = repeatMs;
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ void HAL_StopCANPacketRepeating(HAL_CANHandle handle, int32_t apiId,
|
||||
if (*status != 0) {
|
||||
return;
|
||||
}
|
||||
std::lock_guard<wpi::mutex> lock(can->mapMutex);
|
||||
std::lock_guard lock(can->mapMutex);
|
||||
can->periodicSends[apiId] = -1;
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ void HAL_ReadCANPacketNew(HAL_CANHandle handle, int32_t apiId, uint8_t* data,
|
||||
HAL_CAN_ReceiveMessage(&messageId, 0x1FFFFFFF, data, &dataSize, &ts, status);
|
||||
|
||||
if (*status == 0) {
|
||||
std::lock_guard<wpi::mutex> lock(can->mapMutex);
|
||||
std::lock_guard lock(can->mapMutex);
|
||||
auto& msg = can->receives[messageId];
|
||||
msg.length = dataSize;
|
||||
msg.lastTimeStamp = ts;
|
||||
@@ -197,7 +197,7 @@ void HAL_ReadCANPacketLatest(HAL_CANHandle handle, int32_t apiId, uint8_t* data,
|
||||
uint32_t ts = 0;
|
||||
HAL_CAN_ReceiveMessage(&messageId, 0x1FFFFFFF, data, &dataSize, &ts, status);
|
||||
|
||||
std::lock_guard<wpi::mutex> lock(can->mapMutex);
|
||||
std::lock_guard lock(can->mapMutex);
|
||||
if (*status == 0) {
|
||||
// fresh update
|
||||
auto& msg = can->receives[messageId];
|
||||
@@ -234,7 +234,7 @@ void HAL_ReadCANPacketTimeout(HAL_CANHandle handle, int32_t apiId,
|
||||
uint32_t ts = 0;
|
||||
HAL_CAN_ReceiveMessage(&messageId, 0x1FFFFFFF, data, &dataSize, &ts, status);
|
||||
|
||||
std::lock_guard<wpi::mutex> lock(can->mapMutex);
|
||||
std::lock_guard lock(can->mapMutex);
|
||||
if (*status == 0) {
|
||||
// fresh update
|
||||
auto& msg = can->receives[messageId];
|
||||
@@ -276,7 +276,7 @@ void HAL_ReadCANPeriodicPacket(HAL_CANHandle handle, int32_t apiId,
|
||||
uint32_t messageId = CreateCANId(can.get(), apiId);
|
||||
|
||||
{
|
||||
std::lock_guard<wpi::mutex> lock(can->mapMutex);
|
||||
std::lock_guard lock(can->mapMutex);
|
||||
auto i = can->receives.find(messageId);
|
||||
if (i != can->receives.end()) {
|
||||
// Found, check if new enough
|
||||
@@ -296,7 +296,7 @@ void HAL_ReadCANPeriodicPacket(HAL_CANHandle handle, int32_t apiId,
|
||||
uint32_t ts = 0;
|
||||
HAL_CAN_ReceiveMessage(&messageId, 0x1FFFFFFF, data, &dataSize, &ts, status);
|
||||
|
||||
std::lock_guard<wpi::mutex> lock(can->mapMutex);
|
||||
std::lock_guard lock(can->mapMutex);
|
||||
if (*status == 0) {
|
||||
// fresh update
|
||||
auto& msg = can->receives[messageId];
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-2019 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. */
|
||||
@@ -69,7 +69,7 @@ HAL_DigitalHandle HAL_InitializeDIOPort(HAL_PortHandle portHandle,
|
||||
|
||||
port->channel = static_cast<uint8_t>(channel);
|
||||
|
||||
std::lock_guard<wpi::mutex> lock(digitalDIOMutex);
|
||||
std::lock_guard lock(digitalDIOMutex);
|
||||
|
||||
tDIO::tOutputEnable outputEnable = digitalSystem->readOutputEnable(status);
|
||||
|
||||
@@ -143,7 +143,7 @@ void HAL_FreeDIOPort(HAL_DigitalHandle dioPortHandle) {
|
||||
}
|
||||
|
||||
int32_t status = 0;
|
||||
std::lock_guard<wpi::mutex> lock(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<wpi::mutex> lock(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
|
||||
@@ -251,7 +251,7 @@ void HAL_SetDIO(HAL_DigitalHandle dioPortHandle, HAL_Bool value,
|
||||
if (value != 0) value = 1;
|
||||
}
|
||||
{
|
||||
std::lock_guard<wpi::mutex> lock(digitalDIOMutex);
|
||||
std::lock_guard lock(digitalDIOMutex);
|
||||
tDIO::tDO currentDIO = digitalSystem->readDO(status);
|
||||
|
||||
if (port->channel >= kNumDigitalHeaders + kNumDigitalMXPChannels) {
|
||||
@@ -289,7 +289,7 @@ void HAL_SetDIODirection(HAL_DigitalHandle dioPortHandle, HAL_Bool input,
|
||||
return;
|
||||
}
|
||||
{
|
||||
std::lock_guard<wpi::mutex> lock(digitalDIOMutex);
|
||||
std::lock_guard lock(digitalDIOMutex);
|
||||
tDIO::tOutputEnable currentDIO = digitalSystem->readOutputEnable(status);
|
||||
|
||||
if (port->channel >= kNumDigitalHeaders + kNumDigitalMXPChannels) {
|
||||
@@ -421,7 +421,7 @@ void HAL_SetFilterSelect(HAL_DigitalHandle dioPortHandle, int32_t filterIndex,
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard<wpi::mutex> lock(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,
|
||||
@@ -441,7 +441,7 @@ int32_t HAL_GetFilterSelect(HAL_DigitalHandle dioPortHandle, int32_t* status) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::lock_guard<wpi::mutex> lock(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(
|
||||
@@ -457,7 +457,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> lock(digitalDIOMutex);
|
||||
std::lock_guard lock(digitalDIOMutex);
|
||||
digitalSystem->writeFilterPeriodHdr(filterIndex, value, status);
|
||||
if (*status == 0) {
|
||||
digitalSystem->writeFilterPeriodMXP(filterIndex, value, status);
|
||||
@@ -470,7 +470,7 @@ int64_t HAL_GetFilterPeriod(int32_t filterIndex, int32_t* status) {
|
||||
uint32_t hdrPeriod = 0;
|
||||
uint32_t mxpPeriod = 0;
|
||||
{
|
||||
std::lock_guard<wpi::mutex> lock(digitalDIOMutex);
|
||||
std::lock_guard lock(digitalDIOMutex);
|
||||
hdrPeriod = digitalSystem->readFilterPeriodHdr(filterIndex, status);
|
||||
if (*status == 0) {
|
||||
mxpPeriod = digitalSystem->readFilterPeriodMXP(filterIndex, status);
|
||||
|
||||
@@ -74,7 +74,7 @@ void initializeDigital(int32_t* status) {
|
||||
// Initial check, as if it's true initialization has finished
|
||||
if (initialized) return;
|
||||
|
||||
std::lock_guard<wpi::mutex> lock(initializeMutex);
|
||||
std::lock_guard lock(initializeMutex);
|
||||
// Second check in case another thread was waiting
|
||||
if (initialized) return;
|
||||
|
||||
|
||||
@@ -180,7 +180,7 @@ static int32_t HAL_GetMatchInfoInternal(HAL_MatchInfo* info) {
|
||||
static void UpdateDriverStationControlWord(bool force,
|
||||
HAL_ControlWord& controlWord) {
|
||||
auto now = std::chrono::steady_clock::now();
|
||||
std::lock_guard<wpi::mutex> lock(m_controlWordMutex);
|
||||
std::lock_guard lock(m_controlWordMutex);
|
||||
// Update every 50 ms or on force.
|
||||
if ((now - m_lastControlWordUpdate > std::chrono::milliseconds(50)) ||
|
||||
force) {
|
||||
@@ -207,7 +207,7 @@ static void UpdateDriverStationDataCaches() {
|
||||
|
||||
{
|
||||
// Obtain a lock on the data, swap the cached data into the main data arrays
|
||||
std::lock_guard<wpi::mutex> lock(m_cacheDataMutex);
|
||||
std::lock_guard lock(m_cacheDataMutex);
|
||||
|
||||
m_joystickAxes.swap(m_joystickAxesCache);
|
||||
m_joystickPOVs.swap(m_joystickPOVsCache);
|
||||
@@ -220,7 +220,7 @@ static void UpdateDriverStationDataCaches() {
|
||||
class DriverStationThread : public wpi::SafeThread {
|
||||
public:
|
||||
void Main() {
|
||||
std::unique_lock<wpi::mutex> lock(m_mutex);
|
||||
std::unique_lock lock(m_mutex);
|
||||
while (m_active) {
|
||||
m_cond.wait(lock, [&] { return !m_active || m_notify; });
|
||||
if (!m_active) break;
|
||||
@@ -272,7 +272,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<wpi::mutex> lock(msgMutex);
|
||||
std::lock_guard lock(msgMutex);
|
||||
static std::string prevMsg[KEEP_MSGS];
|
||||
static std::chrono::time_point<std::chrono::steady_clock>
|
||||
prevMsgTime[KEEP_MSGS];
|
||||
@@ -363,33 +363,33 @@ int32_t HAL_GetControlWord(HAL_ControlWord* controlWord) {
|
||||
}
|
||||
|
||||
int32_t HAL_GetJoystickAxes(int32_t joystickNum, HAL_JoystickAxes* axes) {
|
||||
std::unique_lock<wpi::mutex> lock(m_cacheDataMutex);
|
||||
std::unique_lock lock(m_cacheDataMutex);
|
||||
*axes = m_joystickAxes[joystickNum];
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t HAL_GetJoystickPOVs(int32_t joystickNum, HAL_JoystickPOVs* povs) {
|
||||
std::unique_lock<wpi::mutex> lock(m_cacheDataMutex);
|
||||
std::unique_lock lock(m_cacheDataMutex);
|
||||
*povs = m_joystickPOVs[joystickNum];
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t HAL_GetJoystickButtons(int32_t joystickNum,
|
||||
HAL_JoystickButtons* buttons) {
|
||||
std::unique_lock<wpi::mutex> lock(m_cacheDataMutex);
|
||||
std::unique_lock lock(m_cacheDataMutex);
|
||||
*buttons = m_joystickButtons[joystickNum];
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t HAL_GetJoystickDescriptor(int32_t joystickNum,
|
||||
HAL_JoystickDescriptor* desc) {
|
||||
std::unique_lock<wpi::mutex> lock(m_cacheDataMutex);
|
||||
std::unique_lock lock(m_cacheDataMutex);
|
||||
*desc = m_joystickDescriptor[joystickNum];
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t HAL_GetMatchInfo(HAL_MatchInfo* info) {
|
||||
std::unique_lock<wpi::mutex> lock(m_cacheDataMutex);
|
||||
std::unique_lock lock(m_cacheDataMutex);
|
||||
*info = *m_matchInfo;
|
||||
return 0;
|
||||
}
|
||||
@@ -545,7 +545,7 @@ void HAL_InitializeDriverStation(void) {
|
||||
// Initial check, as if it's true initialization has finished
|
||||
if (initialized) return;
|
||||
|
||||
std::lock_guard<wpi::mutex> lock(initializeMutex);
|
||||
std::lock_guard lock(initializeMutex);
|
||||
// Second check in case another thread was waiting
|
||||
if (initialized) return;
|
||||
|
||||
|
||||
@@ -282,7 +282,7 @@ void HAL_BaseInitialize(int32_t* status) {
|
||||
// Initial check, as if it's true initialization has finished
|
||||
if (initialized) return;
|
||||
|
||||
std::lock_guard<wpi::mutex> lock(initializeMutex);
|
||||
std::lock_guard 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
|
||||
@@ -341,7 +341,7 @@ HAL_Bool HAL_Initialize(int32_t timeout, int32_t mode) {
|
||||
// Initial check, as if it's true initialization has finished
|
||||
if (initialized) return true;
|
||||
|
||||
std::lock_guard<wpi::mutex> lock(initializeMutex);
|
||||
std::lock_guard lock(initializeMutex);
|
||||
// Second check in case another thread was waiting
|
||||
if (initialized) return true;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-2019 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. */
|
||||
@@ -52,7 +52,7 @@ void HAL_InitializeI2C(HAL_I2CPort port, int32_t* status) {
|
||||
}
|
||||
|
||||
if (port == HAL_I2C_kOnboard) {
|
||||
std::lock_guard<wpi::mutex> lock(digitalI2COnBoardMutex);
|
||||
std::lock_guard lock(digitalI2COnBoardMutex);
|
||||
i2COnboardObjCount++;
|
||||
if (i2COnboardObjCount > 1) return;
|
||||
int handle = open("/dev/i2c-2", O_RDWR);
|
||||
@@ -62,7 +62,7 @@ void HAL_InitializeI2C(HAL_I2CPort port, int32_t* status) {
|
||||
}
|
||||
i2COnBoardHandle = handle;
|
||||
} else {
|
||||
std::lock_guard<wpi::mutex> lock(digitalI2CMXPMutex);
|
||||
std::lock_guard lock(digitalI2CMXPMutex);
|
||||
i2CMXPObjCount++;
|
||||
if (i2CMXPObjCount > 1) return;
|
||||
if ((i2CMXPDigitalHandle1 = HAL_InitializeDIOPort(
|
||||
@@ -108,10 +108,10 @@ int32_t HAL_TransactionI2C(HAL_I2CPort port, int32_t deviceAddress,
|
||||
rdwr.nmsgs = 2;
|
||||
|
||||
if (port == HAL_I2C_kOnboard) {
|
||||
std::lock_guard<wpi::mutex> lock(digitalI2COnBoardMutex);
|
||||
std::lock_guard lock(digitalI2COnBoardMutex);
|
||||
return ioctl(i2COnBoardHandle, I2C_RDWR, &rdwr);
|
||||
} else {
|
||||
std::lock_guard<wpi::mutex> lock(digitalI2CMXPMutex);
|
||||
std::lock_guard lock(digitalI2CMXPMutex);
|
||||
return ioctl(i2CMXPHandle, I2C_RDWR, &rdwr);
|
||||
}
|
||||
}
|
||||
@@ -134,10 +134,10 @@ int32_t HAL_WriteI2C(HAL_I2CPort port, int32_t deviceAddress,
|
||||
rdwr.nmsgs = 1;
|
||||
|
||||
if (port == HAL_I2C_kOnboard) {
|
||||
std::lock_guard<wpi::mutex> lock(digitalI2COnBoardMutex);
|
||||
std::lock_guard lock(digitalI2COnBoardMutex);
|
||||
return ioctl(i2COnBoardHandle, I2C_RDWR, &rdwr);
|
||||
} else {
|
||||
std::lock_guard<wpi::mutex> lock(digitalI2CMXPMutex);
|
||||
std::lock_guard lock(digitalI2CMXPMutex);
|
||||
return ioctl(i2CMXPHandle, I2C_RDWR, &rdwr);
|
||||
}
|
||||
}
|
||||
@@ -160,10 +160,10 @@ int32_t HAL_ReadI2C(HAL_I2CPort port, int32_t deviceAddress, uint8_t* buffer,
|
||||
rdwr.nmsgs = 1;
|
||||
|
||||
if (port == HAL_I2C_kOnboard) {
|
||||
std::lock_guard<wpi::mutex> lock(digitalI2COnBoardMutex);
|
||||
std::lock_guard lock(digitalI2COnBoardMutex);
|
||||
return ioctl(i2COnBoardHandle, I2C_RDWR, &rdwr);
|
||||
} else {
|
||||
std::lock_guard<wpi::mutex> lock(digitalI2CMXPMutex);
|
||||
std::lock_guard lock(digitalI2CMXPMutex);
|
||||
return ioctl(i2CMXPHandle, I2C_RDWR, &rdwr);
|
||||
}
|
||||
}
|
||||
@@ -175,12 +175,12 @@ void HAL_CloseI2C(HAL_I2CPort port) {
|
||||
}
|
||||
|
||||
if (port == HAL_I2C_kOnboard) {
|
||||
std::lock_guard<wpi::mutex> lock(digitalI2COnBoardMutex);
|
||||
std::lock_guard lock(digitalI2COnBoardMutex);
|
||||
if (i2COnboardObjCount-- == 0) {
|
||||
close(i2COnBoardHandle);
|
||||
}
|
||||
} else {
|
||||
std::lock_guard<wpi::mutex> lock(digitalI2CMXPMutex);
|
||||
std::lock_guard lock(digitalI2CMXPMutex);
|
||||
if (i2CMXPObjCount-- == 0) {
|
||||
close(i2CMXPHandle);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-2019 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. */
|
||||
@@ -26,7 +26,7 @@ namespace {
|
||||
class InterruptThread : public wpi::SafeThread {
|
||||
public:
|
||||
void Main() {
|
||||
std::unique_lock<wpi::mutex> lock(m_mutex);
|
||||
std::unique_lock lock(m_mutex);
|
||||
while (m_active) {
|
||||
m_cond.wait(lock, [&] { return !m_active || m_notify; });
|
||||
if (!m_active) break;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-2019 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. */
|
||||
@@ -53,7 +53,7 @@ class NotifierHandleContainer
|
||||
~NotifierHandleContainer() {
|
||||
ForEach([](HAL_NotifierHandle handle, Notifier* notifier) {
|
||||
{
|
||||
std::lock_guard<wpi::mutex> lock(notifier->mutex);
|
||||
std::lock_guard lock(notifier->mutex);
|
||||
notifier->triggerTime = UINT64_MAX;
|
||||
notifier->triggeredTime = 0;
|
||||
notifier->active = false;
|
||||
@@ -66,7 +66,7 @@ class NotifierHandleContainer
|
||||
static NotifierHandleContainer* notifierHandles;
|
||||
|
||||
static void alarmCallback(uint32_t, void*) {
|
||||
std::lock_guard<wpi::mutex> lock(notifierMutex);
|
||||
std::lock_guard lock(notifierMutex);
|
||||
int32_t status = 0;
|
||||
uint64_t currentTime = 0;
|
||||
|
||||
@@ -77,7 +77,7 @@ static void alarmCallback(uint32_t, void*) {
|
||||
notifierHandles->ForEach([&](HAL_NotifierHandle handle, Notifier* notifier) {
|
||||
if (notifier->triggerTime == UINT64_MAX) return;
|
||||
if (currentTime == 0) currentTime = HAL_GetFPGATime(&status);
|
||||
std::unique_lock<wpi::mutex> lock(notifier->mutex);
|
||||
std::unique_lock lock(notifier->mutex);
|
||||
if (notifier->triggerTime < currentTime) {
|
||||
notifier->triggerTime = UINT64_MAX;
|
||||
notifier->triggeredTime = currentTime;
|
||||
@@ -119,7 +119,7 @@ HAL_NotifierHandle HAL_InitializeNotifier(int32_t* status) {
|
||||
std::atexit(cleanupNotifierAtExit);
|
||||
|
||||
if (notifierRefCount.fetch_add(1) == 0) {
|
||||
std::lock_guard<wpi::mutex> lock(notifierMutex);
|
||||
std::lock_guard lock(notifierMutex);
|
||||
// create manager and alarm if not already created
|
||||
if (!notifierManager) {
|
||||
notifierManager = std::make_unique<tInterruptManager>(
|
||||
@@ -144,7 +144,7 @@ void HAL_StopNotifier(HAL_NotifierHandle notifierHandle, int32_t* status) {
|
||||
if (!notifier) return;
|
||||
|
||||
{
|
||||
std::lock_guard<wpi::mutex> lock(notifier->mutex);
|
||||
std::lock_guard lock(notifier->mutex);
|
||||
notifier->triggerTime = UINT64_MAX;
|
||||
notifier->triggeredTime = 0;
|
||||
notifier->active = false;
|
||||
@@ -158,7 +158,7 @@ void HAL_CleanNotifier(HAL_NotifierHandle notifierHandle, int32_t* status) {
|
||||
|
||||
// Just in case HAL_StopNotifier() wasn't called...
|
||||
{
|
||||
std::lock_guard<wpi::mutex> lock(notifier->mutex);
|
||||
std::lock_guard lock(notifier->mutex);
|
||||
notifier->triggerTime = UINT64_MAX;
|
||||
notifier->triggeredTime = 0;
|
||||
notifier->active = false;
|
||||
@@ -177,7 +177,7 @@ void HAL_CleanNotifier(HAL_NotifierHandle notifierHandle, int32_t* status) {
|
||||
// if (notifierAlarm) notifierAlarm->writeEnable(false, status);
|
||||
// if (notifierManager) notifierManager->disable(status);
|
||||
|
||||
// std::lock_guard<wpi::mutex> lock(notifierMutex);
|
||||
// std::lock_guard lock(notifierMutex);
|
||||
// notifierAlarm = nullptr;
|
||||
// notifierManager = nullptr;
|
||||
// closestTrigger = UINT64_MAX;
|
||||
@@ -190,12 +190,12 @@ void HAL_UpdateNotifierAlarm(HAL_NotifierHandle notifierHandle,
|
||||
if (!notifier) return;
|
||||
|
||||
{
|
||||
std::lock_guard<wpi::mutex> lock(notifier->mutex);
|
||||
std::lock_guard lock(notifier->mutex);
|
||||
notifier->triggerTime = triggerTime;
|
||||
notifier->triggeredTime = UINT64_MAX;
|
||||
}
|
||||
|
||||
std::lock_guard<wpi::mutex> lock(notifierMutex);
|
||||
std::lock_guard lock(notifierMutex);
|
||||
// Update alarm time if closer than current.
|
||||
if (triggerTime < closestTrigger) {
|
||||
bool wasActive = (closestTrigger != UINT64_MAX);
|
||||
@@ -214,7 +214,7 @@ void HAL_CancelNotifierAlarm(HAL_NotifierHandle notifierHandle,
|
||||
if (!notifier) return;
|
||||
|
||||
{
|
||||
std::lock_guard<wpi::mutex> lock(notifier->mutex);
|
||||
std::lock_guard lock(notifier->mutex);
|
||||
notifier->triggerTime = UINT64_MAX;
|
||||
}
|
||||
}
|
||||
@@ -223,7 +223,7 @@ uint64_t HAL_WaitForNotifierAlarm(HAL_NotifierHandle notifierHandle,
|
||||
int32_t* status) {
|
||||
auto notifier = notifierHandles->Get(notifierHandle);
|
||||
if (!notifier) return 0;
|
||||
std::unique_lock<wpi::mutex> lock(notifier->mutex);
|
||||
std::unique_lock lock(notifier->mutex);
|
||||
notifier->cond.wait(lock, [&] {
|
||||
return !notifier->active || notifier->triggeredTime != UINT64_MAX;
|
||||
});
|
||||
|
||||
@@ -130,7 +130,7 @@ HAL_PDPHandle HAL_InitializePDP(int32_t module, int32_t* status) {
|
||||
return HAL_kInvalidHandle;
|
||||
}
|
||||
|
||||
std::lock_guard<wpi::mutex> lock(pdpHandleMutex);
|
||||
std::lock_guard lock(pdpHandleMutex);
|
||||
|
||||
if (pdpHandles[module] != HAL_kInvalidHandle) {
|
||||
*status = 0;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-2019 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. */
|
||||
@@ -100,7 +100,7 @@ void HAL_SetRelay(HAL_RelayHandle relayPortHandle, HAL_Bool on,
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
std::lock_guard<wpi::mutex> lock(digitalRelayMutex);
|
||||
std::lock_guard lock(digitalRelayMutex);
|
||||
uint8_t relays = 0;
|
||||
if (port->fwd) {
|
||||
relays = relaySystem->readValue_Forward(status);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-2019 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. */
|
||||
@@ -55,7 +55,7 @@ static bool SPIInUseByAuto(HAL_SPIPort port) {
|
||||
// There are two SPI devices: one for ports 0-3 (onboard), the other for port
|
||||
// 4 (MXP).
|
||||
if (!spiAutoRunning) return false;
|
||||
std::lock_guard<wpi::mutex> lock(spiAutoMutex);
|
||||
std::lock_guard lock(spiAutoMutex);
|
||||
return (spiAutoPort >= 0 && spiAutoPort <= 3 && port >= 0 && port <= 3) ||
|
||||
(spiAutoPort == 4 && port == 4);
|
||||
}
|
||||
@@ -253,7 +253,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> lock(spiApiMutexes[port]);
|
||||
std::lock_guard lock(spiApiMutexes[port]);
|
||||
return ioctl(HAL_GetSPIHandle(port), SPI_IOC_MESSAGE(1), &xfer);
|
||||
}
|
||||
|
||||
@@ -270,7 +270,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> lock(spiApiMutexes[port]);
|
||||
std::lock_guard lock(spiApiMutexes[port]);
|
||||
return ioctl(HAL_GetSPIHandle(port), SPI_IOC_MESSAGE(1), &xfer);
|
||||
}
|
||||
|
||||
@@ -286,7 +286,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> lock(spiApiMutexes[port]);
|
||||
std::lock_guard lock(spiApiMutexes[port]);
|
||||
return ioctl(HAL_GetSPIHandle(port), SPI_IOC_MESSAGE(1), &xfer);
|
||||
}
|
||||
|
||||
@@ -299,7 +299,7 @@ void HAL_CloseSPI(HAL_SPIPort port) {
|
||||
HAL_FreeSPIAuto(port, &status);
|
||||
|
||||
{
|
||||
std::lock_guard<wpi::mutex> lock(spiApiMutexes[port]);
|
||||
std::lock_guard lock(spiApiMutexes[port]);
|
||||
close(HAL_GetSPIHandle(port));
|
||||
}
|
||||
|
||||
@@ -335,7 +335,7 @@ void HAL_SetSPISpeed(HAL_SPIPort port, int32_t speed) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard<wpi::mutex> lock(spiApiMutexes[port]);
|
||||
std::lock_guard lock(spiApiMutexes[port]);
|
||||
ioctl(HAL_GetSPIHandle(port), SPI_IOC_WR_MAX_SPEED_HZ, &speed);
|
||||
}
|
||||
|
||||
@@ -350,7 +350,7 @@ void HAL_SetSPIOpts(HAL_SPIPort port, HAL_Bool msbFirst,
|
||||
mode |= (clkIdleHigh ? 2 : 0);
|
||||
mode |= (sampleOnTrailing ? 1 : 0);
|
||||
|
||||
std::lock_guard<wpi::mutex> lock(spiApiMutexes[port]);
|
||||
std::lock_guard lock(spiApiMutexes[port]);
|
||||
ioctl(HAL_GetSPIHandle(port), SPI_IOC_WR_MODE, &mode);
|
||||
}
|
||||
|
||||
@@ -360,7 +360,7 @@ void HAL_SetSPIChipSelectActiveHigh(HAL_SPIPort port, int32_t* status) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard<wpi::mutex> lock(spiApiMutexes[port]);
|
||||
std::lock_guard lock(spiApiMutexes[port]);
|
||||
if (port < 4) {
|
||||
spiSystem->writeChipSelectActiveHigh_Hdr(
|
||||
spiSystem->readChipSelectActiveHigh_Hdr(status) | (1 << port), status);
|
||||
@@ -375,7 +375,7 @@ void HAL_SetSPIChipSelectActiveLow(HAL_SPIPort port, int32_t* status) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard<wpi::mutex> lock(spiApiMutexes[port]);
|
||||
std::lock_guard lock(spiApiMutexes[port]);
|
||||
if (port < 4) {
|
||||
spiSystem->writeChipSelectActiveHigh_Hdr(
|
||||
spiSystem->readChipSelectActiveHigh_Hdr(status) & ~(1 << port), status);
|
||||
@@ -389,7 +389,7 @@ int32_t HAL_GetSPIHandle(HAL_SPIPort port) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::lock_guard<wpi::mutex> lock(spiHandleMutexes[port]);
|
||||
std::lock_guard lock(spiHandleMutexes[port]);
|
||||
switch (port) {
|
||||
case 0:
|
||||
return m_spiCS0Handle;
|
||||
@@ -411,7 +411,7 @@ void HAL_SetSPIHandle(HAL_SPIPort port, int32_t handle) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard<wpi::mutex> lock(spiHandleMutexes[port]);
|
||||
std::lock_guard lock(spiHandleMutexes[port]);
|
||||
switch (port) {
|
||||
case 0:
|
||||
m_spiCS0Handle = handle;
|
||||
@@ -439,7 +439,7 @@ void HAL_InitSPIAuto(HAL_SPIPort port, int32_t bufferSize, int32_t* status) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard<wpi::mutex> lock(spiAutoMutex);
|
||||
std::lock_guard lock(spiAutoMutex);
|
||||
// FPGA only has one auto SPI engine
|
||||
if (spiAutoPort != kSpiMaxHandles) {
|
||||
*status = RESOURCE_IS_ALLOCATED;
|
||||
@@ -470,7 +470,7 @@ void HAL_FreeSPIAuto(HAL_SPIPort port, int32_t* status) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard<wpi::mutex> lock(spiAutoMutex);
|
||||
std::lock_guard lock(spiAutoMutex);
|
||||
if (spiAutoPort != port) return;
|
||||
spiAutoPort = kSpiMaxHandles;
|
||||
|
||||
@@ -487,7 +487,7 @@ void HAL_FreeSPIAuto(HAL_SPIPort port, int32_t* status) {
|
||||
}
|
||||
|
||||
void HAL_StartSPIAutoRate(HAL_SPIPort port, double period, int32_t* status) {
|
||||
std::lock_guard<wpi::mutex> lock(spiAutoMutex);
|
||||
std::lock_guard lock(spiAutoMutex);
|
||||
// FPGA only has one auto SPI engine
|
||||
if (port != spiAutoPort) {
|
||||
*status = INCOMPATIBLE_STATE;
|
||||
@@ -510,7 +510,7 @@ void HAL_StartSPIAutoTrigger(HAL_SPIPort port, HAL_Handle digitalSourceHandle,
|
||||
HAL_AnalogTriggerType analogTriggerType,
|
||||
HAL_Bool triggerRising, HAL_Bool triggerFalling,
|
||||
int32_t* status) {
|
||||
std::lock_guard<wpi::mutex> lock(spiAutoMutex);
|
||||
std::lock_guard lock(spiAutoMutex);
|
||||
// FPGA only has one auto SPI engine
|
||||
if (port != spiAutoPort) {
|
||||
*status = INCOMPATIBLE_STATE;
|
||||
@@ -545,7 +545,7 @@ void HAL_StartSPIAutoTrigger(HAL_SPIPort port, HAL_Handle digitalSourceHandle,
|
||||
}
|
||||
|
||||
void HAL_StopSPIAuto(HAL_SPIPort port, int32_t* status) {
|
||||
std::lock_guard<wpi::mutex> lock(spiAutoMutex);
|
||||
std::lock_guard lock(spiAutoMutex);
|
||||
// FPGA only has one auto SPI engine
|
||||
if (port != spiAutoPort) {
|
||||
*status = INCOMPATIBLE_STATE;
|
||||
@@ -575,7 +575,7 @@ void HAL_SetSPIAutoTransmitData(HAL_SPIPort port, const uint8_t* dataToSend,
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard<wpi::mutex> lock(spiAutoMutex);
|
||||
std::lock_guard lock(spiAutoMutex);
|
||||
// FPGA only has one auto SPI engine
|
||||
if (port != spiAutoPort) {
|
||||
*status = INCOMPATIBLE_STATE;
|
||||
@@ -594,7 +594,7 @@ void HAL_SetSPIAutoTransmitData(HAL_SPIPort port, const uint8_t* dataToSend,
|
||||
}
|
||||
|
||||
void HAL_ForceSPIAutoRead(HAL_SPIPort port, int32_t* status) {
|
||||
std::lock_guard<wpi::mutex> lock(spiAutoMutex);
|
||||
std::lock_guard lock(spiAutoMutex);
|
||||
// FPGA only has one auto SPI engine
|
||||
if (port != spiAutoPort) {
|
||||
*status = INCOMPATIBLE_STATE;
|
||||
@@ -607,7 +607,7 @@ void HAL_ForceSPIAutoRead(HAL_SPIPort port, int32_t* status) {
|
||||
int32_t HAL_ReadSPIAutoReceivedData(HAL_SPIPort port, uint32_t* buffer,
|
||||
int32_t numToRead, double timeout,
|
||||
int32_t* status) {
|
||||
std::lock_guard<wpi::mutex> lock(spiAutoMutex);
|
||||
std::lock_guard lock(spiAutoMutex);
|
||||
// FPGA only has one auto SPI engine
|
||||
if (port != spiAutoPort) {
|
||||
*status = INCOMPATIBLE_STATE;
|
||||
@@ -621,7 +621,7 @@ int32_t HAL_ReadSPIAutoReceivedData(HAL_SPIPort port, uint32_t* buffer,
|
||||
}
|
||||
|
||||
int32_t HAL_GetSPIAutoDroppedCount(HAL_SPIPort port, int32_t* status) {
|
||||
std::lock_guard<wpi::mutex> lock(spiAutoMutex);
|
||||
std::lock_guard lock(spiAutoMutex);
|
||||
// FPGA only has one auto SPI engine
|
||||
if (port != spiAutoPort) {
|
||||
*status = INCOMPATIBLE_STATE;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-2019 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. */
|
||||
@@ -275,7 +275,7 @@ done:
|
||||
|
||||
int32_t SerialHelper::GetIndexForPort(HAL_SerialPort port, int32_t* status) {
|
||||
// Hold lock whenever we're using the names array
|
||||
std::lock_guard<wpi::mutex> lock(m_nameMutex);
|
||||
std::lock_guard lock(m_nameMutex);
|
||||
|
||||
std::string portString = m_usbNames[port - 2];
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ CTR_Code CtreCanNode::GetRx(uint32_t arbId,uint8_t * dataBytes, uint32_t timeout
|
||||
if(timeoutMs > 999)
|
||||
timeoutMs = 999;
|
||||
FRC_NetworkCommunication_CANSessionMux_receiveMessage(&arbId,kFullMessageIDMask,dataBytes,&len,&timeStamp,&status);
|
||||
std::lock_guard<wpi::mutex> lock(_lck);
|
||||
std::lock_guard lock(_lck);
|
||||
if(status == 0){
|
||||
/* fresh update */
|
||||
rxEvent_t & r = _rxRxEvents[arbId]; /* lookup entry or make a default new one with all zeroes */
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-2019 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. */
|
||||
@@ -17,7 +17,7 @@ static wpi::SmallVector<HandleBase*, 32>* globalHandles = nullptr;
|
||||
static wpi::mutex globalHandleMutex;
|
||||
HandleBase::HandleBase() {
|
||||
static wpi::SmallVector<HandleBase*, 32> gH;
|
||||
std::lock_guard<wpi::mutex> lock(globalHandleMutex);
|
||||
std::lock_guard lock(globalHandleMutex);
|
||||
if (!globalHandles) {
|
||||
globalHandles = &gH;
|
||||
}
|
||||
@@ -30,7 +30,7 @@ HandleBase::HandleBase() {
|
||||
}
|
||||
}
|
||||
HandleBase::~HandleBase() {
|
||||
std::lock_guard<wpi::mutex> lock(globalHandleMutex);
|
||||
std::lock_guard lock(globalHandleMutex);
|
||||
auto index = std::find(globalHandles->begin(), globalHandles->end(), this);
|
||||
if (index != globalHandles->end()) {
|
||||
*index = nullptr;
|
||||
@@ -43,7 +43,7 @@ void HandleBase::ResetHandles() {
|
||||
}
|
||||
}
|
||||
void HandleBase::ResetGlobalHandles() {
|
||||
std::unique_lock<wpi::mutex> lock(globalHandleMutex);
|
||||
std::unique_lock lock(globalHandleMutex);
|
||||
for (auto&& i : *globalHandles) {
|
||||
if (i != nullptr) {
|
||||
lock.unlock();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-2019 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. */
|
||||
@@ -88,7 +88,7 @@ void InterruptThreadJNI::Main() {
|
||||
reinterpret_cast<void**>(&env), &args);
|
||||
if (rs != JNI_OK) return;
|
||||
|
||||
std::unique_lock<wpi::mutex> lock(m_mutex);
|
||||
std::unique_lock lock(m_mutex);
|
||||
while (m_active) {
|
||||
m_cond.wait(lock, [&] { return !m_active || m_notify; });
|
||||
if (!m_active) break;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2017-2019 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. */
|
||||
@@ -77,7 +77,7 @@ void UnsafeManipulateDIO(HAL_DigitalHandle handle, int32_t* status,
|
||||
tDIO* dSys = detail::UnsafeGetDigialSystem();
|
||||
auto mask = detail::ComputeDigitalMask(handle, status);
|
||||
if (status != 0) return;
|
||||
std::lock_guard<wpi::mutex> lock(dioMutex);
|
||||
std::lock_guard lock(dioMutex);
|
||||
|
||||
tDIO::tOutputEnable enableOE = dSys->readOutputEnable(status);
|
||||
enableOE.value |= mask;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-2019 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. */
|
||||
@@ -59,7 +59,7 @@ THandle DigitalHandleResource<THandle, TStruct, size>::Allocate(
|
||||
*status = RESOURCE_OUT_OF_RANGE;
|
||||
return HAL_kInvalidHandle;
|
||||
}
|
||||
std::lock_guard<wpi::mutex> lock(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;
|
||||
@@ -77,7 +77,7 @@ std::shared_ptr<TStruct> DigitalHandleResource<THandle, TStruct, size>::Get(
|
||||
if (index < 0 || index >= size) {
|
||||
return nullptr;
|
||||
}
|
||||
std::lock_guard<wpi::mutex> lock(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];
|
||||
@@ -90,14 +90,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> lock(m_handleMutexes[index]);
|
||||
std::lock_guard 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> lock(m_handleMutexes[i]);
|
||||
std::lock_guard lock(m_handleMutexes[i]);
|
||||
m_structures[i].reset();
|
||||
}
|
||||
HandleBase::ResetHandles();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-2019 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. */
|
||||
@@ -66,7 +66,7 @@ IndexedClassedHandleResource<THandle, TStruct, size, enumValue>::Allocate(
|
||||
*status = RESOURCE_OUT_OF_RANGE;
|
||||
return HAL_kInvalidHandle;
|
||||
}
|
||||
std::lock_guard<wpi::mutex> lock(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;
|
||||
@@ -86,7 +86,7 @@ IndexedClassedHandleResource<THandle, TStruct, size, enumValue>::Get(
|
||||
if (index < 0 || index >= size) {
|
||||
return nullptr;
|
||||
}
|
||||
std::lock_guard<wpi::mutex> lock(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];
|
||||
@@ -100,7 +100,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> lock(m_handleMutexes[index]);
|
||||
std::lock_guard lock(m_handleMutexes[index]);
|
||||
m_structures[index].reset();
|
||||
}
|
||||
|
||||
@@ -109,7 +109,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> lock(m_handleMutexes[i]);
|
||||
std::lock_guard lock(m_handleMutexes[i]);
|
||||
m_structures[i].reset();
|
||||
}
|
||||
HandleBase::ResetHandles();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-2019 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. */
|
||||
@@ -61,7 +61,7 @@ THandle IndexedHandleResource<THandle, TStruct, size, enumValue>::Allocate(
|
||||
*status = RESOURCE_OUT_OF_RANGE;
|
||||
return HAL_kInvalidHandle;
|
||||
}
|
||||
std::lock_guard<wpi::mutex> lock(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;
|
||||
@@ -80,7 +80,7 @@ IndexedHandleResource<THandle, TStruct, size, enumValue>::Get(THandle handle) {
|
||||
if (index < 0 || index >= size) {
|
||||
return nullptr;
|
||||
}
|
||||
std::lock_guard<wpi::mutex> lock(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];
|
||||
@@ -94,7 +94,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> lock(m_handleMutexes[index]);
|
||||
std::lock_guard lock(m_handleMutexes[index]);
|
||||
m_structures[index].reset();
|
||||
}
|
||||
|
||||
@@ -102,7 +102,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> lock(m_handleMutexes[i]);
|
||||
std::lock_guard lock(m_handleMutexes[i]);
|
||||
m_structures[i].reset();
|
||||
}
|
||||
HandleBase::ResetHandles();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-2019 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. */
|
||||
@@ -58,12 +58,12 @@ THandle
|
||||
LimitedClassedHandleResource<THandle, TStruct, size, enumValue>::Allocate(
|
||||
std::shared_ptr<TStruct> toSet) {
|
||||
// globally lock to loop through indices
|
||||
std::lock_guard<wpi::mutex> lock(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<wpi::mutex> lock(m_handleMutexes[i]);
|
||||
std::lock_guard lock(m_handleMutexes[i]);
|
||||
m_structures[i] = toSet;
|
||||
return static_cast<THandle>(createHandle(i, enumValue, m_version));
|
||||
}
|
||||
@@ -81,7 +81,7 @@ LimitedClassedHandleResource<THandle, TStruct, size, enumValue>::Get(
|
||||
if (index < 0 || index >= size) {
|
||||
return nullptr;
|
||||
}
|
||||
std::lock_guard<wpi::mutex> lock(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,8 +95,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> allocateLock(m_allocateMutex);
|
||||
std::lock_guard<wpi::mutex> handleLock(m_handleMutexes[index]);
|
||||
std::lock_guard allocateLock(m_allocateMutex);
|
||||
std::lock_guard handleLock(m_handleMutexes[index]);
|
||||
m_structures[index].reset();
|
||||
}
|
||||
|
||||
@@ -105,9 +105,9 @@ template <typename THandle, typename TStruct, int16_t size,
|
||||
void LimitedClassedHandleResource<THandle, TStruct, size,
|
||||
enumValue>::ResetHandles() {
|
||||
{
|
||||
std::lock_guard<wpi::mutex> allocateLock(m_allocateMutex);
|
||||
std::lock_guard allocateLock(m_allocateMutex);
|
||||
for (int i = 0; i < size; i++) {
|
||||
std::lock_guard<wpi::mutex> handleLock(m_handleMutexes[i]);
|
||||
std::lock_guard handleLock(m_handleMutexes[i]);
|
||||
m_structures[i].reset();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-2019 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. */
|
||||
@@ -54,12 +54,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> lock(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<wpi::mutex> lock(m_handleMutexes[i]);
|
||||
std::lock_guard lock(m_handleMutexes[i]);
|
||||
m_structures[i] = std::make_shared<TStruct>();
|
||||
return static_cast<THandle>(createHandle(i, enumValue, m_version));
|
||||
}
|
||||
@@ -76,7 +76,7 @@ LimitedHandleResource<THandle, TStruct, size, enumValue>::Get(THandle handle) {
|
||||
if (index < 0 || index >= size) {
|
||||
return nullptr;
|
||||
}
|
||||
std::lock_guard<wpi::mutex> lock(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];
|
||||
@@ -90,8 +90,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> allocateLock(m_allocateMutex);
|
||||
std::lock_guard<wpi::mutex> handleLock(m_handleMutexes[index]);
|
||||
std::lock_guard allocateLock(m_allocateMutex);
|
||||
std::lock_guard handleLock(m_handleMutexes[index]);
|
||||
m_structures[index].reset();
|
||||
}
|
||||
|
||||
@@ -99,9 +99,9 @@ template <typename THandle, typename TStruct, int16_t size,
|
||||
HAL_HandleEnum enumValue>
|
||||
void LimitedHandleResource<THandle, TStruct, size, enumValue>::ResetHandles() {
|
||||
{
|
||||
std::lock_guard<wpi::mutex> allocateLock(m_allocateMutex);
|
||||
std::lock_guard allocateLock(m_allocateMutex);
|
||||
for (int i = 0; i < size; i++) {
|
||||
std::lock_guard<wpi::mutex> handleLock(m_handleMutexes[i]);
|
||||
std::lock_guard handleLock(m_handleMutexes[i]);
|
||||
m_structures[i].reset();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2008-2019 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. */
|
||||
@@ -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> lock(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 <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> lock(m_handleMutex);
|
||||
std::lock_guard 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> lock(m_handleMutex);
|
||||
std::lock_guard lock(m_handleMutex);
|
||||
if (index < 0 || index >= static_cast<int16_t>(m_structures.size()))
|
||||
return nullptr;
|
||||
return std::move(m_structures[index]);
|
||||
@@ -101,7 +101,7 @@ UnlimitedHandleResource<THandle, TStruct, enumValue>::Free(THandle handle) {
|
||||
template <typename THandle, typename TStruct, HAL_HandleEnum enumValue>
|
||||
void UnlimitedHandleResource<THandle, TStruct, enumValue>::ResetHandles() {
|
||||
{
|
||||
std::lock_guard<wpi::mutex> lock(m_handleMutex);
|
||||
std::lock_guard lock(m_handleMutex);
|
||||
for (size_t i = 0; i < m_structures.size(); i++) {
|
||||
m_structures[i].reset();
|
||||
}
|
||||
@@ -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> lock(m_handleMutex);
|
||||
std::lock_guard lock(m_handleMutex);
|
||||
size_t i;
|
||||
for (i = 0; i < m_structures.size(); i++) {
|
||||
if (m_structures[i] != nullptr) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2018-2019 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. */
|
||||
@@ -29,12 +29,12 @@ class SimCallbackRegistryBase {
|
||||
|
||||
public:
|
||||
void Cancel(int32_t uid) {
|
||||
std::lock_guard<wpi::recursive_spinlock> lock(m_mutex);
|
||||
std::lock_guard lock(m_mutex);
|
||||
if (m_callbacks) m_callbacks->erase(uid - 1);
|
||||
}
|
||||
|
||||
void Reset() {
|
||||
std::lock_guard<wpi::recursive_spinlock> lock(m_mutex);
|
||||
std::lock_guard lock(m_mutex);
|
||||
DoReset();
|
||||
}
|
||||
|
||||
@@ -68,13 +68,13 @@ template <typename CallbackFunction, const char* (*GetName)()>
|
||||
class SimCallbackRegistry : public impl::SimCallbackRegistryBase {
|
||||
public:
|
||||
int32_t Register(CallbackFunction callback, void* param) {
|
||||
std::lock_guard<wpi::recursive_spinlock> lock(m_mutex);
|
||||
std::lock_guard lock(m_mutex);
|
||||
return DoRegister(reinterpret_cast<RawFunctor>(callback), param);
|
||||
}
|
||||
|
||||
template <typename... U>
|
||||
void Invoke(U&&... u) const {
|
||||
std::lock_guard<wpi::recursive_spinlock> lock(m_mutex);
|
||||
std::lock_guard lock(m_mutex);
|
||||
if (m_callbacks) {
|
||||
const char* name = GetName();
|
||||
for (auto&& cb : *m_callbacks)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2018-2019 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. */
|
||||
@@ -27,14 +27,14 @@ class SimDataValueBase : protected SimCallbackRegistryBase {
|
||||
LLVM_ATTRIBUTE_ALWAYS_INLINE void CancelCallback(int32_t uid) { Cancel(uid); }
|
||||
|
||||
T Get() const {
|
||||
std::lock_guard<wpi::recursive_spinlock> lock(m_mutex);
|
||||
std::lock_guard lock(m_mutex);
|
||||
return m_value;
|
||||
}
|
||||
|
||||
LLVM_ATTRIBUTE_ALWAYS_INLINE operator T() const { return Get(); }
|
||||
|
||||
void Reset(T value) {
|
||||
std::lock_guard<wpi::recursive_spinlock> lock(m_mutex);
|
||||
std::lock_guard lock(m_mutex);
|
||||
DoReset();
|
||||
m_value = value;
|
||||
}
|
||||
@@ -44,7 +44,7 @@ class SimDataValueBase : protected SimCallbackRegistryBase {
|
||||
protected:
|
||||
int32_t DoRegisterCallback(HAL_NotifyCallback callback, void* param,
|
||||
HAL_Bool initialNotify, const char* name) {
|
||||
std::unique_lock<wpi::recursive_spinlock> lock(m_mutex);
|
||||
std::unique_lock lock(m_mutex);
|
||||
int32_t newUid = DoRegister(reinterpret_cast<RawFunctor>(callback), param);
|
||||
if (newUid == -1) return -1;
|
||||
if (initialNotify) {
|
||||
@@ -57,7 +57,7 @@ class SimDataValueBase : protected SimCallbackRegistryBase {
|
||||
}
|
||||
|
||||
void DoSet(T value, const char* name) {
|
||||
std::lock_guard<wpi::recursive_spinlock> lock(this->m_mutex);
|
||||
std::lock_guard lock(this->m_mutex);
|
||||
if (m_value != value) {
|
||||
m_value = value;
|
||||
if (m_callbacks) {
|
||||
|
||||
@@ -100,7 +100,7 @@ HAL_CANHandle HAL_InitializeCAN(HAL_CANManufacturer manufacturer,
|
||||
void HAL_CleanCAN(HAL_CANHandle handle) {
|
||||
auto data = canHandles->Free(handle);
|
||||
|
||||
std::lock_guard<wpi::mutex> lock(data->mapMutex);
|
||||
std::lock_guard lock(data->mapMutex);
|
||||
|
||||
for (auto&& i : data->periodicSends) {
|
||||
int32_t s = 0;
|
||||
@@ -124,7 +124,7 @@ void HAL_WriteCANPacket(HAL_CANHandle handle, const uint8_t* data,
|
||||
if (*status != 0) {
|
||||
return;
|
||||
}
|
||||
std::lock_guard<wpi::mutex> lock(can->mapMutex);
|
||||
std::lock_guard lock(can->mapMutex);
|
||||
can->periodicSends[apiId] = -1;
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ void HAL_WriteCANPacketRepeating(HAL_CANHandle handle, const uint8_t* data,
|
||||
if (*status != 0) {
|
||||
return;
|
||||
}
|
||||
std::lock_guard<wpi::mutex> lock(can->mapMutex);
|
||||
std::lock_guard lock(can->mapMutex);
|
||||
can->periodicSends[apiId] = repeatMs;
|
||||
}
|
||||
|
||||
@@ -162,7 +162,7 @@ void HAL_StopCANPacketRepeating(HAL_CANHandle handle, int32_t apiId,
|
||||
if (*status != 0) {
|
||||
return;
|
||||
}
|
||||
std::lock_guard<wpi::mutex> lock(can->mapMutex);
|
||||
std::lock_guard lock(can->mapMutex);
|
||||
can->periodicSends[apiId] = -1;
|
||||
}
|
||||
|
||||
@@ -181,7 +181,7 @@ void HAL_ReadCANPacketNew(HAL_CANHandle handle, int32_t apiId, uint8_t* data,
|
||||
HAL_CAN_ReceiveMessage(&messageId, 0x1FFFFFFF, data, &dataSize, &ts, status);
|
||||
|
||||
if (*status == 0) {
|
||||
std::lock_guard<wpi::mutex> lock(can->mapMutex);
|
||||
std::lock_guard lock(can->mapMutex);
|
||||
auto& msg = can->receives[messageId];
|
||||
msg.length = dataSize;
|
||||
msg.lastTimeStamp = ts;
|
||||
@@ -206,7 +206,7 @@ void HAL_ReadCANPacketLatest(HAL_CANHandle handle, int32_t apiId, uint8_t* data,
|
||||
uint32_t ts = 0;
|
||||
HAL_CAN_ReceiveMessage(&messageId, 0x1FFFFFFF, data, &dataSize, &ts, status);
|
||||
|
||||
std::lock_guard<wpi::mutex> lock(can->mapMutex);
|
||||
std::lock_guard lock(can->mapMutex);
|
||||
if (*status == 0) {
|
||||
// fresh update
|
||||
auto& msg = can->receives[messageId];
|
||||
@@ -243,7 +243,7 @@ void HAL_ReadCANPacketTimeout(HAL_CANHandle handle, int32_t apiId,
|
||||
uint32_t ts = 0;
|
||||
HAL_CAN_ReceiveMessage(&messageId, 0x1FFFFFFF, data, &dataSize, &ts, status);
|
||||
|
||||
std::lock_guard<wpi::mutex> lock(can->mapMutex);
|
||||
std::lock_guard lock(can->mapMutex);
|
||||
if (*status == 0) {
|
||||
// fresh update
|
||||
auto& msg = can->receives[messageId];
|
||||
@@ -285,7 +285,7 @@ void HAL_ReadCANPeriodicPacket(HAL_CANHandle handle, int32_t apiId,
|
||||
uint32_t messageId = CreateCANId(can.get(), apiId);
|
||||
|
||||
{
|
||||
std::lock_guard<wpi::mutex> lock(can->mapMutex);
|
||||
std::lock_guard lock(can->mapMutex);
|
||||
auto i = can->receives.find(messageId);
|
||||
if (i != can->receives.end()) {
|
||||
// Found, check if new enough
|
||||
@@ -305,7 +305,7 @@ void HAL_ReadCANPeriodicPacket(HAL_CANHandle handle, int32_t apiId,
|
||||
uint32_t ts = 0;
|
||||
HAL_CAN_ReceiveMessage(&messageId, 0x1FFFFFFF, data, &dataSize, &ts, status);
|
||||
|
||||
std::lock_guard<wpi::mutex> lock(can->mapMutex);
|
||||
std::lock_guard lock(can->mapMutex);
|
||||
if (*status == 0) {
|
||||
// fresh update
|
||||
auto& msg = can->receives[messageId];
|
||||
|
||||
@@ -51,7 +51,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<wpi::mutex> lock(msgMutex);
|
||||
std::lock_guard lock(msgMutex);
|
||||
static std::string prevMsg[KEEP_MSGS];
|
||||
static std::chrono::time_point<std::chrono::steady_clock>
|
||||
prevMsgTime[KEEP_MSGS];
|
||||
@@ -223,7 +223,7 @@ HAL_Bool HAL_IsNewControlData(void) {
|
||||
// worth the cycles to check.
|
||||
int currentCount = 0;
|
||||
{
|
||||
std::unique_lock<wpi::mutex> lock(newDSDataAvailableMutex);
|
||||
std::unique_lock lock(newDSDataAvailableMutex);
|
||||
currentCount = newDSDataAvailableCounter;
|
||||
}
|
||||
if (lastCount == currentCount) return false;
|
||||
@@ -240,7 +240,7 @@ HAL_Bool HAL_WaitForDSDataTimeout(double timeout) {
|
||||
auto timeoutTime =
|
||||
std::chrono::steady_clock::now() + std::chrono::duration<double>(timeout);
|
||||
|
||||
std::unique_lock<wpi::mutex> lock(newDSDataAvailableMutex);
|
||||
std::unique_lock lock(newDSDataAvailableMutex);
|
||||
int currentCount = newDSDataAvailableCounter;
|
||||
while (newDSDataAvailableCounter == currentCount) {
|
||||
if (timeout > 0) {
|
||||
@@ -262,7 +262,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<wpi::mutex> lock(newDSDataAvailableMutex);
|
||||
std::lock_guard lock(newDSDataAvailableMutex);
|
||||
// Nofify all threads
|
||||
newDSDataAvailableCounter++;
|
||||
newDSDataAvailableCond->notify_all();
|
||||
@@ -276,7 +276,7 @@ void HAL_InitializeDriverStation(void) {
|
||||
// Initial check, as if it's true initialization has finished
|
||||
if (initialized) return;
|
||||
|
||||
std::lock_guard<wpi::mutex> lock(initializeMutex);
|
||||
std::lock_guard lock(initializeMutex);
|
||||
// Second check in case another thread was waiting
|
||||
if (initialized) return;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-2019 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. */
|
||||
@@ -231,7 +231,7 @@ HAL_Bool HAL_Initialize(int32_t timeout, int32_t mode) {
|
||||
// Initial check, as if it's true initialization has finished
|
||||
if (initialized) return true;
|
||||
|
||||
std::lock_guard<wpi::mutex> lock(initializeMutex);
|
||||
std::lock_guard lock(initializeMutex);
|
||||
// Second check in case another thread was waiting
|
||||
if (initialized) return true;
|
||||
|
||||
|
||||
@@ -223,7 +223,7 @@ static int64_t WaitForInterruptDigital(HAL_InterruptHandle handle,
|
||||
std::chrono::steady_clock::now() + std::chrono::duration<double>(timeout);
|
||||
|
||||
{
|
||||
std::unique_lock<wpi::mutex> lock(waitMutex);
|
||||
std::unique_lock lock(waitMutex);
|
||||
while (!data->waitPredicate) {
|
||||
if (data->waitCond.wait_until(lock, timeoutTime) ==
|
||||
std::cv_status::timeout) {
|
||||
@@ -287,7 +287,7 @@ static int64_t WaitForInterruptAnalog(HAL_InterruptHandle handle,
|
||||
std::chrono::steady_clock::now() + std::chrono::duration<double>(timeout);
|
||||
|
||||
{
|
||||
std::unique_lock<wpi::mutex> lock(waitMutex);
|
||||
std::unique_lock lock(waitMutex);
|
||||
while (!data->waitPredicate) {
|
||||
if (data->waitCond.wait_until(lock, timeoutTime) ==
|
||||
std::cv_status::timeout) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-2019 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. */
|
||||
@@ -38,7 +38,7 @@ class NotifierHandleContainer
|
||||
~NotifierHandleContainer() {
|
||||
ForEach([](HAL_NotifierHandle handle, Notifier* notifier) {
|
||||
{
|
||||
std::lock_guard<wpi::mutex> lock(notifier->mutex);
|
||||
std::lock_guard lock(notifier->mutex);
|
||||
notifier->active = false;
|
||||
notifier->running = false;
|
||||
}
|
||||
@@ -76,7 +76,7 @@ void HAL_StopNotifier(HAL_NotifierHandle notifierHandle, int32_t* status) {
|
||||
if (!notifier) return;
|
||||
|
||||
{
|
||||
std::lock_guard<wpi::mutex> lock(notifier->mutex);
|
||||
std::lock_guard lock(notifier->mutex);
|
||||
notifier->active = false;
|
||||
notifier->running = false;
|
||||
}
|
||||
@@ -89,7 +89,7 @@ void HAL_CleanNotifier(HAL_NotifierHandle notifierHandle, int32_t* status) {
|
||||
|
||||
// Just in case HAL_StopNotifier() wasn't called...
|
||||
{
|
||||
std::lock_guard<wpi::mutex> lock(notifier->mutex);
|
||||
std::lock_guard lock(notifier->mutex);
|
||||
notifier->active = false;
|
||||
notifier->running = false;
|
||||
}
|
||||
@@ -102,7 +102,7 @@ void HAL_UpdateNotifierAlarm(HAL_NotifierHandle notifierHandle,
|
||||
if (!notifier) return;
|
||||
|
||||
{
|
||||
std::lock_guard<wpi::mutex> lock(notifier->mutex);
|
||||
std::lock_guard lock(notifier->mutex);
|
||||
notifier->waitTime = triggerTime;
|
||||
notifier->running = true;
|
||||
notifier->updatedAlarm = true;
|
||||
@@ -118,7 +118,7 @@ void HAL_CancelNotifierAlarm(HAL_NotifierHandle notifierHandle,
|
||||
if (!notifier) return;
|
||||
|
||||
{
|
||||
std::lock_guard<wpi::mutex> lock(notifier->mutex);
|
||||
std::lock_guard lock(notifier->mutex);
|
||||
notifier->running = false;
|
||||
}
|
||||
}
|
||||
@@ -128,7 +128,7 @@ uint64_t HAL_WaitForNotifierAlarm(HAL_NotifierHandle notifierHandle,
|
||||
auto notifier = notifierHandles->Get(notifierHandle);
|
||||
if (!notifier) return 0;
|
||||
|
||||
std::unique_lock<wpi::mutex> lock(notifier->mutex);
|
||||
std::unique_lock lock(notifier->mutex);
|
||||
while (notifier->active) {
|
||||
double waitTime;
|
||||
if (!notifier->running) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2017-2019 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. */
|
||||
@@ -46,7 +46,7 @@ void DriverStationData::ResetData() {
|
||||
matchTime.Reset(0.0);
|
||||
|
||||
{
|
||||
std::lock_guard<wpi::spinlock> lock(m_joystickDataMutex);
|
||||
std::lock_guard 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);
|
||||
@@ -63,7 +63,7 @@ void DriverStationData::ResetData() {
|
||||
}
|
||||
}
|
||||
{
|
||||
std::lock_guard<wpi::spinlock> lock(m_matchInfoMutex);
|
||||
std::lock_guard lock(m_matchInfoMutex);
|
||||
|
||||
m_matchInfo = std::make_unique<HAL_MatchInfo>();
|
||||
}
|
||||
@@ -71,22 +71,22 @@ void DriverStationData::ResetData() {
|
||||
|
||||
void DriverStationData::GetJoystickAxes(int32_t joystickNum,
|
||||
HAL_JoystickAxes* axes) {
|
||||
std::lock_guard<wpi::spinlock> lock(m_joystickDataMutex);
|
||||
std::lock_guard lock(m_joystickDataMutex);
|
||||
*axes = m_joystickAxes[joystickNum];
|
||||
}
|
||||
void DriverStationData::GetJoystickPOVs(int32_t joystickNum,
|
||||
HAL_JoystickPOVs* povs) {
|
||||
std::lock_guard<wpi::spinlock> lock(m_joystickDataMutex);
|
||||
std::lock_guard lock(m_joystickDataMutex);
|
||||
*povs = m_joystickPOVs[joystickNum];
|
||||
}
|
||||
void DriverStationData::GetJoystickButtons(int32_t joystickNum,
|
||||
HAL_JoystickButtons* buttons) {
|
||||
std::lock_guard<wpi::spinlock> lock(m_joystickDataMutex);
|
||||
std::lock_guard lock(m_joystickDataMutex);
|
||||
*buttons = m_joystickButtons[joystickNum];
|
||||
}
|
||||
void DriverStationData::GetJoystickDescriptor(
|
||||
int32_t joystickNum, HAL_JoystickDescriptor* descriptor) {
|
||||
std::lock_guard<wpi::spinlock> lock(m_joystickDataMutex);
|
||||
std::lock_guard lock(m_joystickDataMutex);
|
||||
*descriptor = m_joystickDescriptor[joystickNum];
|
||||
// Always ensure name is null terminated
|
||||
descriptor->name[255] = '\0';
|
||||
@@ -95,49 +95,49 @@ void DriverStationData::GetJoystickOutputs(int32_t joystickNum,
|
||||
int64_t* outputs,
|
||||
int32_t* leftRumble,
|
||||
int32_t* rightRumble) {
|
||||
std::lock_guard<wpi::spinlock> lock(m_joystickDataMutex);
|
||||
std::lock_guard 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<wpi::spinlock> lock(m_matchInfoMutex);
|
||||
std::lock_guard lock(m_matchInfoMutex);
|
||||
*info = *m_matchInfo;
|
||||
}
|
||||
|
||||
void DriverStationData::SetJoystickAxes(int32_t joystickNum,
|
||||
const HAL_JoystickAxes* axes) {
|
||||
std::lock_guard<wpi::spinlock> lock(m_joystickDataMutex);
|
||||
std::lock_guard lock(m_joystickDataMutex);
|
||||
m_joystickAxes[joystickNum] = *axes;
|
||||
}
|
||||
void DriverStationData::SetJoystickPOVs(int32_t joystickNum,
|
||||
const HAL_JoystickPOVs* povs) {
|
||||
std::lock_guard<wpi::spinlock> lock(m_joystickDataMutex);
|
||||
std::lock_guard lock(m_joystickDataMutex);
|
||||
m_joystickPOVs[joystickNum] = *povs;
|
||||
}
|
||||
void DriverStationData::SetJoystickButtons(int32_t joystickNum,
|
||||
const HAL_JoystickButtons* buttons) {
|
||||
std::lock_guard<wpi::spinlock> lock(m_joystickDataMutex);
|
||||
std::lock_guard lock(m_joystickDataMutex);
|
||||
m_joystickButtons[joystickNum] = *buttons;
|
||||
}
|
||||
|
||||
void DriverStationData::SetJoystickDescriptor(
|
||||
int32_t joystickNum, const HAL_JoystickDescriptor* descriptor) {
|
||||
std::lock_guard<wpi::spinlock> lock(m_joystickDataMutex);
|
||||
std::lock_guard 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<wpi::spinlock> lock(m_joystickDataMutex);
|
||||
std::lock_guard 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<wpi::spinlock> lock(m_matchInfoMutex);
|
||||
std::lock_guard lock(m_matchInfoMutex);
|
||||
*m_matchInfo = *info;
|
||||
*(std::end(m_matchInfo->eventName) - 1) = '\0';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user