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

@@ -45,22 +45,31 @@ int64_t Telemetry::Thread::GetValue(CS_Handle handle, CS_TelemetryKind kind,
Telemetry::~Telemetry() {}
void Telemetry::Start() { m_owner.Start(m_notifier); }
void Telemetry::Start() {
m_owner.Start(m_notifier);
}
void Telemetry::Stop() { m_owner.Stop(); }
void Telemetry::Stop() {
m_owner.Stop();
}
void Telemetry::Thread::Main() {
std::unique_lock lock(m_mutex);
auto prevTime = std::chrono::steady_clock::now();
while (m_active) {
double period = m_period;
if (period == 0) period = 1000.0;
if (period == 0) {
period = 1000.0;
}
auto timeoutTime = prevTime + std::chrono::duration<double>(period);
while (m_active && !m_updated) {
if (m_cond.wait_until(lock, timeoutTime) == std::cv_status::timeout)
if (m_cond.wait_until(lock, timeoutTime) == std::cv_status::timeout) {
break;
}
}
if (!m_active) {
break;
}
if (!m_active) break;
if (m_updated) {
m_updated = false;
continue;
@@ -80,8 +89,12 @@ void Telemetry::Thread::Main() {
void Telemetry::SetPeriod(double seconds) {
auto thr = m_owner.GetThread();
if (!thr) return;
if (thr->m_period == seconds) return; // no change
if (!thr) {
return;
}
if (thr->m_period == seconds) {
return; // no change
}
thr->m_period = seconds;
thr->m_updated = true;
thr->m_cond.notify_one();
@@ -89,7 +102,9 @@ void Telemetry::SetPeriod(double seconds) {
double Telemetry::GetElapsedTime() {
auto thr = m_owner.GetThread();
if (!thr) return 0;
if (!thr) {
return 0;
}
return thr->m_elapsed;
}
@@ -110,13 +125,17 @@ double Telemetry::GetAverageValue(CS_Handle handle, CS_TelemetryKind kind,
*status = CS_TELEMETRY_NOT_ENABLED;
return 0;
}
if (thr->m_elapsed == 0) return 0.0;
if (thr->m_elapsed == 0) {
return 0.0;
}
return thr->GetValue(handle, kind, status) / thr->m_elapsed;
}
void Telemetry::RecordSourceBytes(const SourceImpl& source, int quantity) {
auto thr = m_owner.GetThread();
if (!thr) return;
if (!thr) {
return;
}
auto handleData = Instance::GetInstance().FindSource(source);
thr->m_current[std::make_pair(Handle{handleData.first, Handle::kSource},
static_cast<int>(CS_SOURCE_BYTES_RECEIVED))] +=
@@ -125,7 +144,9 @@ void Telemetry::RecordSourceBytes(const SourceImpl& source, int quantity) {
void Telemetry::RecordSourceFrames(const SourceImpl& source, int quantity) {
auto thr = m_owner.GetThread();
if (!thr) return;
if (!thr) {
return;
}
auto handleData = Instance::GetInstance().FindSource(source);
thr->m_current[std::make_pair(Handle{handleData.first, Handle::kSource},
static_cast<int>(CS_SOURCE_FRAMES_RECEIVED))] +=