[libc++] Format the code base (#74334)
This patch runs clang-format on all of libcxx/include and libcxx/src, in
accordance with the RFC discussed at [1]. Follow-up patches will format
the benchmarks, the test suite and remaining parts of the code. I'm
splitting this one into its own patch so the diff is a bit easier to
review.
This patch was generated with:
find libcxx/include libcxx/src -type f \
| grep -v 'module.modulemap.in' \
| grep -v 'CMakeLists.txt' \
| grep -v 'README.txt' \
| grep -v 'libcxx.imp' \
| grep -v '__config_site.in' \
| xargs clang-format -i
A Git merge driver is available in libcxx/utils/clang-format-merge-driver.sh
to help resolve merge and rebase issues across these formatting changes.
[1]: https://discourse.llvm.org/t/rfc-clang-formatting-all-of-libc-once-and-for-all
diff --git a/libcxx/src/mutex.cpp b/libcxx/src/mutex.cpp
index fe7a970..ce85475 100644
--- a/libcxx/src/mutex.cpp
+++ b/libcxx/src/mutex.cpp
@@ -25,164 +25,117 @@
// ~mutex is defined elsewhere
-void
-mutex::lock()
-{
- int ec = __libcpp_mutex_lock(&__m_);
- if (ec)
- __throw_system_error(ec, "mutex lock failed");
+void mutex::lock() {
+ int ec = __libcpp_mutex_lock(&__m_);
+ if (ec)
+ __throw_system_error(ec, "mutex lock failed");
}
-bool
-mutex::try_lock() noexcept
-{
- return __libcpp_mutex_trylock(&__m_);
-}
+bool mutex::try_lock() noexcept { return __libcpp_mutex_trylock(&__m_); }
-void
-mutex::unlock() noexcept
-{
- int ec = __libcpp_mutex_unlock(&__m_);
- (void)ec;
- _LIBCPP_ASSERT_UNCATEGORIZED(ec == 0, "call to mutex::unlock failed");
+void mutex::unlock() noexcept {
+ int ec = __libcpp_mutex_unlock(&__m_);
+ (void)ec;
+ _LIBCPP_ASSERT_UNCATEGORIZED(ec == 0, "call to mutex::unlock failed");
}
// recursive_mutex
-recursive_mutex::recursive_mutex()
-{
- int ec = __libcpp_recursive_mutex_init(&__m_);
- if (ec)
- __throw_system_error(ec, "recursive_mutex constructor failed");
+recursive_mutex::recursive_mutex() {
+ int ec = __libcpp_recursive_mutex_init(&__m_);
+ if (ec)
+ __throw_system_error(ec, "recursive_mutex constructor failed");
}
-recursive_mutex::~recursive_mutex()
-{
- int e = __libcpp_recursive_mutex_destroy(&__m_);
- (void)e;
- _LIBCPP_ASSERT_UNCATEGORIZED(e == 0, "call to ~recursive_mutex() failed");
+recursive_mutex::~recursive_mutex() {
+ int e = __libcpp_recursive_mutex_destroy(&__m_);
+ (void)e;
+ _LIBCPP_ASSERT_UNCATEGORIZED(e == 0, "call to ~recursive_mutex() failed");
}
-void
-recursive_mutex::lock()
-{
- int ec = __libcpp_recursive_mutex_lock(&__m_);
- if (ec)
- __throw_system_error(ec, "recursive_mutex lock failed");
+void recursive_mutex::lock() {
+ int ec = __libcpp_recursive_mutex_lock(&__m_);
+ if (ec)
+ __throw_system_error(ec, "recursive_mutex lock failed");
}
-void
-recursive_mutex::unlock() noexcept
-{
- int e = __libcpp_recursive_mutex_unlock(&__m_);
- (void)e;
- _LIBCPP_ASSERT_UNCATEGORIZED(e == 0, "call to recursive_mutex::unlock() failed");
+void recursive_mutex::unlock() noexcept {
+ int e = __libcpp_recursive_mutex_unlock(&__m_);
+ (void)e;
+ _LIBCPP_ASSERT_UNCATEGORIZED(e == 0, "call to recursive_mutex::unlock() failed");
}
-bool
-recursive_mutex::try_lock() noexcept
-{
- return __libcpp_recursive_mutex_trylock(&__m_);
-}
+bool recursive_mutex::try_lock() noexcept { return __libcpp_recursive_mutex_trylock(&__m_); }
// timed_mutex
-timed_mutex::timed_mutex()
- : __locked_(false)
-{
+timed_mutex::timed_mutex() : __locked_(false) {}
+
+timed_mutex::~timed_mutex() { lock_guard<mutex> _(__m_); }
+
+void timed_mutex::lock() {
+ unique_lock<mutex> lk(__m_);
+ while (__locked_)
+ __cv_.wait(lk);
+ __locked_ = true;
}
-timed_mutex::~timed_mutex()
-{
- lock_guard<mutex> _(__m_);
-}
-
-void
-timed_mutex::lock()
-{
- unique_lock<mutex> lk(__m_);
- while (__locked_)
- __cv_.wait(lk);
+bool timed_mutex::try_lock() noexcept {
+ unique_lock<mutex> lk(__m_, try_to_lock);
+ if (lk.owns_lock() && !__locked_) {
__locked_ = true;
+ return true;
+ }
+ return false;
}
-bool
-timed_mutex::try_lock() noexcept
-{
- unique_lock<mutex> lk(__m_, try_to_lock);
- if (lk.owns_lock() && !__locked_)
- {
- __locked_ = true;
- return true;
- }
- return false;
-}
-
-void
-timed_mutex::unlock() noexcept
-{
- lock_guard<mutex> _(__m_);
- __locked_ = false;
- __cv_.notify_one();
+void timed_mutex::unlock() noexcept {
+ lock_guard<mutex> _(__m_);
+ __locked_ = false;
+ __cv_.notify_one();
}
// recursive_timed_mutex
-recursive_timed_mutex::recursive_timed_mutex()
- : __count_(0),
- __id_{}
-{
+recursive_timed_mutex::recursive_timed_mutex() : __count_(0), __id_{} {}
+
+recursive_timed_mutex::~recursive_timed_mutex() { lock_guard<mutex> _(__m_); }
+
+void recursive_timed_mutex::lock() {
+ __thread_id id = this_thread::get_id();
+ unique_lock<mutex> lk(__m_);
+ if (id == __id_) {
+ if (__count_ == numeric_limits<size_t>::max())
+ __throw_system_error(EAGAIN, "recursive_timed_mutex lock limit reached");
+ ++__count_;
+ return;
+ }
+ while (__count_ != 0)
+ __cv_.wait(lk);
+ __count_ = 1;
+ __id_ = id;
}
-recursive_timed_mutex::~recursive_timed_mutex()
-{
- lock_guard<mutex> _(__m_);
-}
-
-void
-recursive_timed_mutex::lock()
-{
- __thread_id id = this_thread::get_id();
- unique_lock<mutex> lk(__m_);
- if (id ==__id_)
- {
- if (__count_ == numeric_limits<size_t>::max())
- __throw_system_error(EAGAIN, "recursive_timed_mutex lock limit reached");
- ++__count_;
- return;
- }
- while (__count_ != 0)
- __cv_.wait(lk);
- __count_ = 1;
+bool recursive_timed_mutex::try_lock() noexcept {
+ __thread_id id = this_thread::get_id();
+ unique_lock<mutex> lk(__m_, try_to_lock);
+ if (lk.owns_lock() && (__count_ == 0 || id == __id_)) {
+ if (__count_ == numeric_limits<size_t>::max())
+ return false;
+ ++__count_;
__id_ = id;
+ return true;
+ }
+ return false;
}
-bool
-recursive_timed_mutex::try_lock() noexcept
-{
- __thread_id id = this_thread::get_id();
- unique_lock<mutex> lk(__m_, try_to_lock);
- if (lk.owns_lock() && (__count_ == 0 || id == __id_))
- {
- if (__count_ == numeric_limits<size_t>::max())
- return false;
- ++__count_;
- __id_ = id;
- return true;
- }
- return false;
-}
-
-void
-recursive_timed_mutex::unlock() noexcept
-{
- unique_lock<mutex> lk(__m_);
- if (--__count_ == 0)
- {
- __id_.__reset();
- lk.unlock();
- __cv_.notify_one();
- }
+void recursive_timed_mutex::unlock() noexcept {
+ unique_lock<mutex> lk(__m_);
+ if (--__count_ == 0) {
+ __id_.__reset();
+ lk.unlock();
+ __cv_.notify_one();
+ }
}
_LIBCPP_END_NAMESPACE_STD