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

@@ -46,7 +46,9 @@ class InterruptJNI : public wpi::SafeThreadOwner<InterruptThreadJNI> {
void Notify(uint32_t mask) {
auto thr = GetThread();
if (!thr) return;
if (!thr) {
return;
}
thr->m_notify = true;
thr->m_mask = mask;
thr->m_cond.notify_one();
@@ -56,10 +58,16 @@ class InterruptJNI : public wpi::SafeThreadOwner<InterruptThreadJNI> {
void InterruptJNI::SetFunc(JNIEnv* env, jobject func, jmethodID mid,
jobject param) {
auto thr = GetThread();
if (!thr) return;
if (!thr) {
return;
}
// free global references
if (thr->m_func) env->DeleteGlobalRef(thr->m_func);
if (thr->m_param) env->DeleteGlobalRef(thr->m_param);
if (thr->m_func) {
env->DeleteGlobalRef(thr->m_func);
}
if (thr->m_param) {
env->DeleteGlobalRef(thr->m_param);
}
// create global references
thr->m_func = env->NewGlobalRef(func);
thr->m_param = param ? env->NewGlobalRef(param) : nullptr;
@@ -74,14 +82,20 @@ void InterruptThreadJNI::Main() {
args.group = nullptr;
jint rs = GetJVM()->AttachCurrentThreadAsDaemon(
reinterpret_cast<void**>(&env), &args);
if (rs != JNI_OK) return;
if (rs != JNI_OK) {
return;
}
std::unique_lock lock(m_mutex);
while (m_active) {
m_cond.wait(lock, [&] { return !m_active || m_notify; });
if (!m_active) break;
if (!m_active) {
break;
}
m_notify = false;
if (!m_func) continue;
if (!m_func) {
continue;
}
jobject func = m_func;
jmethodID mid = m_mid;
uint32_t mask = m_mask;
@@ -96,8 +110,12 @@ void InterruptThreadJNI::Main() {
}
// free global references
if (m_func) env->DeleteGlobalRef(m_func);
if (m_param) env->DeleteGlobalRef(m_param);
if (m_func) {
env->DeleteGlobalRef(m_func);
}
if (m_param) {
env->DeleteGlobalRef(m_param);
}
GetJVM()->DetachCurrentThread();
}