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:
@@ -18,8 +18,9 @@
|
||||
using namespace frc;
|
||||
|
||||
Notifier::Notifier(std::function<void()> handler) {
|
||||
if (handler == nullptr)
|
||||
if (handler == nullptr) {
|
||||
wpi_setWPIErrorWithContext(NullParameter, "handler must not be nullptr");
|
||||
}
|
||||
m_handler = handler;
|
||||
int32_t status = 0;
|
||||
m_notifier = HAL_InitializeNotifier(&status);
|
||||
@@ -29,9 +30,13 @@ Notifier::Notifier(std::function<void()> handler) {
|
||||
for (;;) {
|
||||
int32_t status = 0;
|
||||
HAL_NotifierHandle notifier = m_notifier.load();
|
||||
if (notifier == 0) break;
|
||||
if (notifier == 0) {
|
||||
break;
|
||||
}
|
||||
uint64_t curTime = HAL_WaitForNotifierAlarm(notifier, &status);
|
||||
if (curTime == 0 || status != 0) break;
|
||||
if (curTime == 0 || status != 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
std::function<void()> handler;
|
||||
{
|
||||
@@ -47,14 +52,17 @@ Notifier::Notifier(std::function<void()> handler) {
|
||||
}
|
||||
|
||||
// call callback
|
||||
if (handler) handler();
|
||||
if (handler) {
|
||||
handler();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Notifier::Notifier(int priority, std::function<void()> handler) {
|
||||
if (handler == nullptr)
|
||||
if (handler == nullptr) {
|
||||
wpi_setWPIErrorWithContext(NullParameter, "handler must not be nullptr");
|
||||
}
|
||||
m_handler = handler;
|
||||
int32_t status = 0;
|
||||
m_notifier = HAL_InitializeNotifier(&status);
|
||||
@@ -65,9 +73,13 @@ Notifier::Notifier(int priority, std::function<void()> handler) {
|
||||
HAL_SetCurrentThreadPriority(true, priority, &status);
|
||||
for (;;) {
|
||||
HAL_NotifierHandle notifier = m_notifier.load();
|
||||
if (notifier == 0) break;
|
||||
if (notifier == 0) {
|
||||
break;
|
||||
}
|
||||
uint64_t curTime = HAL_WaitForNotifierAlarm(notifier, &status);
|
||||
if (curTime == 0 || status != 0) break;
|
||||
if (curTime == 0 || status != 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
std::function<void()> handler;
|
||||
{
|
||||
@@ -83,7 +95,9 @@ Notifier::Notifier(int priority, std::function<void()> handler) {
|
||||
}
|
||||
|
||||
// call callback
|
||||
if (handler) handler();
|
||||
if (handler) {
|
||||
handler();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -96,7 +110,9 @@ Notifier::~Notifier() {
|
||||
wpi_setHALError(status);
|
||||
|
||||
// Join the thread to ensure the handler has exited.
|
||||
if (m_thread.joinable()) m_thread.join();
|
||||
if (m_thread.joinable()) {
|
||||
m_thread.join();
|
||||
}
|
||||
|
||||
HAL_CleanNotifier(handle, &status);
|
||||
}
|
||||
@@ -174,7 +190,9 @@ void Notifier::UpdateAlarm(uint64_t triggerTime) {
|
||||
int32_t status = 0;
|
||||
// Return if we are being destructed, or were not created successfully
|
||||
auto notifier = m_notifier.load();
|
||||
if (notifier == 0) return;
|
||||
if (notifier == 0) {
|
||||
return;
|
||||
}
|
||||
HAL_UpdateNotifierAlarm(notifier, triggerTime, &status);
|
||||
wpi_setHALError(status);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user