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:
@@ -43,8 +43,9 @@ class SimPeriodicCallbackRegistry : public impl::SimCallbackRegistryBase {
|
||||
std::scoped_lock lock(m_mutex);
|
||||
#endif
|
||||
if (m_callbacks) {
|
||||
for (auto&& cb : *m_callbacks)
|
||||
for (auto&& cb : *m_callbacks) {
|
||||
reinterpret_cast<HALSIM_SimPeriodicCallback>(cb.callback)(cb.param);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -122,14 +123,20 @@ extern "C" {
|
||||
|
||||
HAL_PortHandle HAL_GetPort(int32_t channel) {
|
||||
// Dont allow a number that wouldn't fit in a uint8_t
|
||||
if (channel < 0 || channel >= 255) return HAL_kInvalidHandle;
|
||||
if (channel < 0 || channel >= 255) {
|
||||
return HAL_kInvalidHandle;
|
||||
}
|
||||
return createPortHandle(channel, 1);
|
||||
}
|
||||
|
||||
HAL_PortHandle HAL_GetPortWithModule(int32_t module, int32_t channel) {
|
||||
// Dont allow a number that wouldn't fit in a uint8_t
|
||||
if (channel < 0 || channel >= 255) return HAL_kInvalidHandle;
|
||||
if (module < 0 || module >= 255) return HAL_kInvalidHandle;
|
||||
if (channel < 0 || channel >= 255) {
|
||||
return HAL_kInvalidHandle;
|
||||
}
|
||||
if (module < 0 || module >= 255) {
|
||||
return HAL_kInvalidHandle;
|
||||
}
|
||||
return createPortHandle(channel, module);
|
||||
}
|
||||
|
||||
@@ -250,9 +257,13 @@ const char* HAL_GetErrorMessage(int32_t code) {
|
||||
}
|
||||
}
|
||||
|
||||
HAL_RuntimeType HAL_GetRuntimeType(void) { return runtimeType; }
|
||||
HAL_RuntimeType HAL_GetRuntimeType(void) {
|
||||
return runtimeType;
|
||||
}
|
||||
|
||||
void HALSIM_SetRuntimeType(HAL_RuntimeType type) { runtimeType = type; }
|
||||
void HALSIM_SetRuntimeType(HAL_RuntimeType type) {
|
||||
runtimeType = type;
|
||||
}
|
||||
|
||||
int32_t HAL_GetFPGAVersion(int32_t* status) {
|
||||
return 2018; // Automatically script this at some point
|
||||
@@ -262,13 +273,17 @@ int64_t HAL_GetFPGARevision(int32_t* status) {
|
||||
return 0; // TODO: Find a better number to return;
|
||||
}
|
||||
|
||||
uint64_t HAL_GetFPGATime(int32_t* status) { return hal::GetFPGATime(); }
|
||||
uint64_t HAL_GetFPGATime(int32_t* status) {
|
||||
return hal::GetFPGATime();
|
||||
}
|
||||
|
||||
uint64_t HAL_ExpandFPGATime(uint32_t unexpanded_lower, int32_t* status) {
|
||||
// Capture the current FPGA time. This will give us the upper half of the
|
||||
// clock.
|
||||
uint64_t fpga_time = HAL_GetFPGATime(status);
|
||||
if (*status != 0) return 0;
|
||||
if (*status != 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Now, we need to detect the case where the lower bits rolled over after we
|
||||
// sampled. In that case, the upper bits will be 1 bigger than they should
|
||||
@@ -302,11 +317,15 @@ HAL_Bool HAL_Initialize(int32_t timeout, int32_t mode) {
|
||||
static std::atomic_bool initialized{false};
|
||||
static wpi::mutex initializeMutex;
|
||||
// Initial check, as if it's true initialization has finished
|
||||
if (initialized) return true;
|
||||
if (initialized) {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::scoped_lock lock(initializeMutex);
|
||||
// Second check in case another thread was waiting
|
||||
if (initialized) return true;
|
||||
if (initialized) {
|
||||
return true;
|
||||
}
|
||||
|
||||
hal::init::InitializeHAL();
|
||||
|
||||
@@ -334,7 +353,9 @@ HAL_Bool HAL_Initialize(int32_t timeout, int32_t mode) {
|
||||
#endif // _WIN32
|
||||
|
||||
wpi::outs().SetUnbuffered();
|
||||
if (HAL_LoadExtensions() < 0) return false;
|
||||
if (HAL_LoadExtensions() < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true; // Add initialization if we need to at a later point
|
||||
}
|
||||
@@ -355,9 +376,13 @@ void HAL_OnShutdown(void* param, void (*func)(void*)) {
|
||||
gOnShutdown.emplace_back(param, func);
|
||||
}
|
||||
|
||||
void HAL_SimPeriodicBefore(void) { gSimPeriodicBefore(); }
|
||||
void HAL_SimPeriodicBefore(void) {
|
||||
gSimPeriodicBefore();
|
||||
}
|
||||
|
||||
void HAL_SimPeriodicAfter(void) { gSimPeriodicAfter(); }
|
||||
void HAL_SimPeriodicAfter(void) {
|
||||
gSimPeriodicAfter();
|
||||
}
|
||||
|
||||
int32_t HALSIM_RegisterSimPeriodicBeforeCallback(
|
||||
HALSIM_SimPeriodicCallback callback, void* param) {
|
||||
|
||||
Reference in New Issue
Block a user