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

@@ -60,7 +60,9 @@ Watchdog::Impl::~Impl() {
wpi_setGlobalHALError(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);
}
@@ -69,15 +71,18 @@ void Watchdog::Impl::UpdateAlarm() {
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 (m_watchdogs.empty())
if (notifier == 0) {
return;
}
if (m_watchdogs.empty()) {
HAL_CancelNotifierAlarm(notifier, &status);
else
} else {
HAL_UpdateNotifierAlarm(
notifier,
static_cast<uint64_t>(m_watchdogs.top()->m_expirationTime.to<double>() *
1e6),
&status);
}
wpi_setGlobalHALError(status);
}
@@ -85,13 +90,19 @@ void Watchdog::Impl::Main() {
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::unique_lock lock(m_mutex);
if (m_watchdogs.empty()) continue;
if (m_watchdogs.empty()) {
continue;
}
// If the condition variable timed out, that means a Watchdog timeout
// has occurred, so call its timeout function.
@@ -128,9 +139,13 @@ Watchdog::Watchdog(double timeout, std::function<void()> callback)
Watchdog::Watchdog(units::second_t timeout, std::function<void()> callback)
: m_timeout(timeout), m_callback(callback), m_impl(GetImpl()) {}
Watchdog::~Watchdog() { Disable(); }
Watchdog::~Watchdog() {
Disable();
}
Watchdog::Watchdog(Watchdog&& rhs) { *this = std::move(rhs); }
Watchdog::Watchdog(Watchdog&& rhs) {
*this = std::move(rhs);
}
Watchdog& Watchdog::operator=(Watchdog&& rhs) {
m_impl = rhs.m_impl;
@@ -186,9 +201,13 @@ void Watchdog::AddEpoch(wpi::StringRef epochName) {
m_tracer.AddEpoch(epochName);
}
void Watchdog::PrintEpochs() { m_tracer.PrintEpochs(); }
void Watchdog::PrintEpochs() {
m_tracer.PrintEpochs();
}
void Watchdog::Reset() { Enable(); }
void Watchdog::Reset() {
Enable();
}
void Watchdog::Enable() {
m_startTime = frc2::Timer::GetFPGATimestamp();