[libcxx-commits] [libcxx] [libc++] Handle threads-related .cpp files like we do all other source files (PR #71100)

via libcxx-commits libcxx-commits at lists.llvm.org
Thu Nov 2 13:22:28 PDT 2023


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff 29fd9bab2c9d04b90def77151961c02c940b15bb 412d9b2e144ccf117ec80338c6c4ba0c1bb23ec0 -- libcxx/src/call_once.cpp libcxx/src/shared_mutex.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/libcxx/src/call_once.cpp b/libcxx/src/call_once.cpp
index 352cdcccdee0..b596518a6540 100644
--- a/libcxx/src/call_once.cpp
+++ b/libcxx/src/call_once.cpp
@@ -24,47 +24,45 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 // keep in sync with:  7741191.
 
 #ifndef _LIBCPP_HAS_NO_THREADS
-static constinit __libcpp_mutex_t mut = _LIBCPP_MUTEX_INITIALIZER;
+static constinit __libcpp_mutex_t mut  = _LIBCPP_MUTEX_INITIALIZER;
 static constinit __libcpp_condvar_t cv = _LIBCPP_CONDVAR_INITIALIZER;
 #endif
 
-void __call_once(volatile once_flag::_State_type& flag, void* arg,
-                 void (*func)(void*))
-{
+void __call_once(volatile once_flag::_State_type& flag, void* arg, void (*func)(void*)) {
 #if defined(_LIBCPP_HAS_NO_THREADS)
 
-    if (flag == once_flag::_Unset) {
-        auto guard = std::__make_exception_guard([&flag] { flag = once_flag::_Unset; });
-        flag = once_flag::_Pending;
-        func(arg);
-        flag = once_flag::_Complete;
-        guard.__complete();
-    }
+  if (flag == once_flag::_Unset) {
+    auto guard = std::__make_exception_guard([&flag] { flag = once_flag::_Unset; });
+    flag       = once_flag::_Pending;
+    func(arg);
+    flag = once_flag::_Complete;
+    guard.__complete();
+  }
 
 #else // !_LIBCPP_HAS_NO_THREADS
 
-    __libcpp_mutex_lock(&mut);
-    while (flag == once_flag::_Pending)
-        __libcpp_condvar_wait(&cv, &mut);
-    if (flag == once_flag::_Unset) {
-        auto guard = std::__make_exception_guard([&flag] {
-            __libcpp_mutex_lock(&mut);
-            __libcpp_relaxed_store(&flag, once_flag::_Unset);
-            __libcpp_mutex_unlock(&mut);
-            __libcpp_condvar_broadcast(&cv);
-        });
+  __libcpp_mutex_lock(&mut);
+  while (flag == once_flag::_Pending)
+    __libcpp_condvar_wait(&cv, &mut);
+  if (flag == once_flag::_Unset) {
+    auto guard = std::__make_exception_guard([&flag] {
+      __libcpp_mutex_lock(&mut);
+      __libcpp_relaxed_store(&flag, once_flag::_Unset);
+      __libcpp_mutex_unlock(&mut);
+      __libcpp_condvar_broadcast(&cv);
+    });
 
-        __libcpp_relaxed_store(&flag, once_flag::_Pending);
-        __libcpp_mutex_unlock(&mut);
-        func(arg);
-        __libcpp_mutex_lock(&mut);
-        __libcpp_atomic_store(&flag, once_flag::_Complete, _AO_Release);
-        __libcpp_mutex_unlock(&mut);
-        __libcpp_condvar_broadcast(&cv);
-        guard.__complete();
-    } else {
-        __libcpp_mutex_unlock(&mut);
-    }
+    __libcpp_relaxed_store(&flag, once_flag::_Pending);
+    __libcpp_mutex_unlock(&mut);
+    func(arg);
+    __libcpp_mutex_lock(&mut);
+    __libcpp_atomic_store(&flag, once_flag::_Complete, _AO_Release);
+    __libcpp_mutex_unlock(&mut);
+    __libcpp_condvar_broadcast(&cv);
+    guard.__complete();
+  } else {
+    __libcpp_mutex_unlock(&mut);
+  }
 
 #endif // !_LIBCPP_HAS_NO_THREADS
 }

``````````

</details>


https://github.com/llvm/llvm-project/pull/71100


More information about the libcxx-commits mailing list