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:
Peter Johnson
2020-12-28 12:58:06 -08:00
committed by GitHub
parent 0291a3ff56
commit 2aed432b4b
634 changed files with 10716 additions and 3938 deletions

View File

@@ -158,7 +158,8 @@ int32_t HAL_SendError(HAL_Bool isError, int32_t errorCode, HAL_Bool isLVCode,
auto curTime = std::chrono::steady_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)) {
@@ -304,7 +305,9 @@ char* HAL_GetJoystickName(int32_t joystickNum) {
}
}
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) {
HAL_JoystickDescriptor joystickDesc;
@@ -360,7 +363,9 @@ 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;
}
@@ -368,7 +373,9 @@ HAL_Bool HAL_IsNewControlData(void) {
/**
* Waits for the newest DS packet to arrive. Note that this is a blocking call.
*/
void HAL_WaitForDSData(void) { HAL_WaitForDSDataTimeout(0); }
void HAL_WaitForDSData(void) {
HAL_WaitForDSDataTimeout(0);
}
/**
* Waits for the newest DS packet to arrive. If timeout is <= 0, this will wait
@@ -406,7 +413,9 @@ constexpr int32_t refNumber = 42;
static void newDataOccur(uint32_t refNum) {
// Since we could get other values, require our specific handle
// to signal our threads
if (refNum != refNumber) return;
if (refNum != refNumber) {
return;
}
std::scoped_lock lock{*newDSDataAvailableMutex};
// Notify all threads
++newDSDataAvailableCounter;
@@ -422,11 +431,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;
}
// Set up the occur function internally with NetComm
NetCommRPCProxy_SetOccurFuncPointer(newDataOccur);
@@ -440,6 +453,8 @@ void HAL_InitializeDriverStation(void) {
* Releases the DS Mutex to allow proper shutdown of any threads that are
* waiting on it.
*/
void HAL_ReleaseDSMutex(void) { newDataOccur(refNumber); }
void HAL_ReleaseDSMutex(void) {
newDataOccur(refNumber);
}
} // extern "C"