mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
Add braces to C++ single-line loops and conditionals (NFC) (#2973)
This makes code easier to read and more consistent between C++ and Java. Also update clang-format settings to always add a line break (even if no braces are used).
This commit is contained in:
@@ -56,9 +56,10 @@ int32_t HAL_SendError(HAL_Bool isError, int32_t errorCode, HAL_Bool isLVCode,
|
||||
const char* details, const char* location,
|
||||
const char* callStack, HAL_Bool printMsg) {
|
||||
auto errorHandler = sendErrorHandler.load();
|
||||
if (errorHandler)
|
||||
if (errorHandler) {
|
||||
return errorHandler(isError, errorCode, isLVCode, details, location,
|
||||
callStack, printMsg);
|
||||
}
|
||||
// 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;
|
||||
@@ -76,7 +77,9 @@ int32_t HAL_SendError(HAL_Bool isError, int32_t errorCode, HAL_Bool isLVCode,
|
||||
auto curTime = fpga_clock::now();
|
||||
int i;
|
||||
for (i = 0; i < KEEP_MSGS; ++i) {
|
||||
if (prevMsg[i] == details) break;
|
||||
if (prevMsg[i] == details) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
int retval = 0;
|
||||
if (i == KEEP_MSGS || (curTime - prevMsgTime[i]) >= std::chrono::seconds(1)) {
|
||||
@@ -177,9 +180,13 @@ char* HAL_GetJoystickName(int32_t joystickNum) {
|
||||
return name;
|
||||
}
|
||||
|
||||
void HAL_FreeJoystickName(char* name) { std::free(name); }
|
||||
void HAL_FreeJoystickName(char* name) {
|
||||
std::free(name);
|
||||
}
|
||||
|
||||
int32_t HAL_GetJoystickAxisType(int32_t joystickNum, int32_t axis) { return 0; }
|
||||
int32_t HAL_GetJoystickAxisType(int32_t joystickNum, int32_t axis) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t HAL_SetJoystickOutputs(int32_t joystickNum, int64_t outputs,
|
||||
int32_t leftRumble, int32_t rightRumble) {
|
||||
@@ -197,7 +204,9 @@ int32_t HAL_GetMatchInfo(HAL_MatchInfo* info) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void HAL_ObserveUserProgramStarting(void) { HALSIM_SetProgramStarted(); }
|
||||
void HAL_ObserveUserProgramStarting(void) {
|
||||
HALSIM_SetProgramStarted();
|
||||
}
|
||||
|
||||
void HAL_ObserveUserProgramDisabled(void) {
|
||||
// TODO
|
||||
@@ -228,12 +237,16 @@ HAL_Bool HAL_IsNewControlData(void) {
|
||||
std::scoped_lock lock(newDSDataAvailableMutex);
|
||||
int& lastCount = GetThreadLocalLastCount();
|
||||
int currentCount = newDSDataAvailableCounter;
|
||||
if (lastCount == currentCount) return false;
|
||||
if (lastCount == currentCount) {
|
||||
return false;
|
||||
}
|
||||
lastCount = currentCount;
|
||||
return true;
|
||||
}
|
||||
|
||||
void HAL_WaitForDSData(void) { HAL_WaitForDSDataTimeout(0); }
|
||||
void HAL_WaitForDSData(void) {
|
||||
HAL_WaitForDSDataTimeout(0);
|
||||
}
|
||||
|
||||
HAL_Bool HAL_WaitForDSDataTimeout(double timeout) {
|
||||
std::unique_lock lock(newDSDataAvailableMutex);
|
||||
@@ -270,7 +283,9 @@ constexpr int32_t refNumber = 42;
|
||||
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;
|
||||
if (refNum != refNumber) {
|
||||
return 0;
|
||||
}
|
||||
SimDriverStationData->CallNewDataCallbacks();
|
||||
std::scoped_lock lock(newDSDataAvailableMutex);
|
||||
// Nofify all threads
|
||||
@@ -284,11 +299,15 @@ void HAL_InitializeDriverStation(void) {
|
||||
static std::atomic_bool initialized{false};
|
||||
static wpi::mutex initializeMutex;
|
||||
// Initial check, as if it's true initialization has finished
|
||||
if (initialized) return;
|
||||
if (initialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::scoped_lock lock(initializeMutex);
|
||||
// Second check in case another thread was waiting
|
||||
if (initialized) return;
|
||||
if (initialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
SimDriverStationData->ResetData();
|
||||
|
||||
@@ -300,6 +319,8 @@ void HAL_InitializeDriverStation(void) {
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
void HAL_ReleaseDSMutex(void) { newDataOccur(refNumber); }
|
||||
void HAL_ReleaseDSMutex(void) {
|
||||
newDataOccur(refNumber);
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
Reference in New Issue
Block a user