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

@@ -27,8 +27,11 @@ class spinlock {
LLVM_ATTRIBUTE_ALWAYS_INLINE
void lock() {
for (unsigned int i = 1; !try_lock(); ++i)
if ((i & 0xff) == 0) std::this_thread::yield();
for (unsigned int i = 1; !try_lock(); ++i) {
if ((i & 0xff) == 0) {
std::this_thread::yield();
}
}
}
LLVM_ATTRIBUTE_ALWAYS_INLINE
@@ -55,8 +58,9 @@ class recursive_spinlock1 {
std::memory_order_release);
} else {
if (owner_thread_id.load(std::memory_order_acquire) !=
std::this_thread::get_id())
std::this_thread::get_id()) {
return false;
}
}
++recursive_counter;
return true;
@@ -64,8 +68,11 @@ class recursive_spinlock1 {
LLVM_ATTRIBUTE_ALWAYS_INLINE
void lock() {
for (unsigned int i = 1; !try_lock(); ++i)
if ((i & 0xffff) == 0) std::this_thread::yield();
for (unsigned int i = 1; !try_lock(); ++i) {
if ((i & 0xffff) == 0) {
std::this_thread::yield();
}
}
}
LLVM_ATTRIBUTE_ALWAYS_INLINE
@@ -97,7 +104,9 @@ class recursive_spinlock2 {
auto us = std::this_thread::get_id();
if (!owner_thread_id.compare_exchange_weak(owner, us,
std::memory_order_acquire)) {
if (owner != us) return false;
if (owner != us) {
return false;
}
}
++recursive_counter;
return true;
@@ -105,8 +114,11 @@ class recursive_spinlock2 {
LLVM_ATTRIBUTE_ALWAYS_INLINE
void lock() {
for (unsigned int i = 1; !try_lock(); ++i)
if ((i & 0xffff) == 0) std::this_thread::yield();
for (unsigned int i = 1; !try_lock(); ++i) {
if ((i & 0xffff) == 0) {
std::this_thread::yield();
}
}
}
LLVM_ATTRIBUTE_ALWAYS_INLINE
@@ -115,8 +127,9 @@ class recursive_spinlock2 {
std::this_thread::get_id());
assert(recursive_counter > 0);
if (--recursive_counter == 0)
if (--recursive_counter == 0) {
owner_thread_id.store(std::thread::id{}, std::memory_order_release);
}
}
};