[libc-commits] [libc] [libc] implement recursive mutex and fix wrong initializer (PR #193992)

via libc-commits libc-commits at lists.llvm.org
Fri Apr 24 08:31:22 PDT 2026


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 origin/main HEAD --extensions h,cpp -- libc/include/llvm-libc-macros/pthread-macros.h libc/include/llvm-libc-types/__mutex_type.h libc/src/__support/threads/fork_callbacks.cpp libc/src/__support/threads/linux/barrier.cpp libc/src/__support/threads/mutex_common.h libc/src/__support/threads/thread.cpp libc/src/__support/threads/unix_mutex.h libc/src/pthread/pthread_mutex_init.cpp libc/src/stdlib/atexit.cpp libc/src/threads/mtx_init.cpp libc/test/integration/src/pthread/pthread_mutex_test.cpp libc/test/integration/src/threads/mtx_test.cpp --diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

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

``````````diff
diff --git a/libc/include/llvm-libc-macros/pthread-macros.h b/libc/include/llvm-libc-macros/pthread-macros.h
index 5fb8857ef..1619ad123 100644
--- a/libc/include/llvm-libc-macros/pthread-macros.h
+++ b/libc/include/llvm-libc-macros/pthread-macros.h
@@ -32,18 +32,18 @@
 #ifdef __linux__
 #define PTHREAD_MUTEX_INITIALIZER                                              \
   {                                                                            \
-      /* .__ftxw = */ {0},           /* .__priority_inherit = */ 0,            \
-      /* .__recursive = */ 0,        /* .__robust = */ 0,                      \
-      /* .__pshared = */ 0,          /* .__owner = */ 0,                       \
-      /* .__lock_count = */ 0,                                              \
+      /* .__ftxw = */ {0},     /* .__priority_inherit = */ 0,                  \
+      /* .__recursive = */ 0,  /* .__robust = */ 0,                            \
+      /* .__pshared = */ 0,    /* .__owner = */ 0,                             \
+      /* .__lock_count = */ 0,                                                 \
   }
 #else
 #define PTHREAD_MUTEX_INITIALIZER                                              \
   {                                                                            \
-      /* .__ftxw = */ {0},           /* .__priority_inherit = */ 0,            \
-      /* .__recursive = */ 0,        /* .__robust = */ 0,                      \
-      /* .__pshared = */ 0,          /* .__owner = */ 0,                       \
-      /* .__lock_count = */ 0,                                              \
+      /* .__ftxw = */ {0},     /* .__priority_inherit = */ 0,                  \
+      /* .__recursive = */ 0,  /* .__robust = */ 0,                            \
+      /* .__pshared = */ 0,    /* .__owner = */ 0,                             \
+      /* .__lock_count = */ 0,                                                 \
   }
 #endif
 
diff --git a/libc/test/integration/src/pthread/pthread_mutex_test.cpp b/libc/test/integration/src/pthread/pthread_mutex_test.cpp
index f45c5f1fb..7e3231894 100644
--- a/libc/test/integration/src/pthread/pthread_mutex_test.cpp
+++ b/libc/test/integration/src/pthread/pthread_mutex_test.cpp
@@ -168,9 +168,9 @@ void recursive_mutex_test() {
   pthread_mutexattr_t attr;
   pthread_mutex_t recursive_mutex;
   ASSERT_EQ(LIBC_NAMESPACE::pthread_mutexattr_init(&attr), 0);
-  ASSERT_EQ(LIBC_NAMESPACE::pthread_mutexattr_settype(&attr,
-                                                      PTHREAD_MUTEX_RECURSIVE),
-            0);
+  ASSERT_EQ(
+      LIBC_NAMESPACE::pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE),
+      0);
   ASSERT_EQ(LIBC_NAMESPACE::pthread_mutex_init(&recursive_mutex, &attr), 0);
   ASSERT_EQ(LIBC_NAMESPACE::pthread_mutexattr_destroy(&attr), 0);
 
@@ -183,8 +183,8 @@ void recursive_mutex_test() {
   ASSERT_EQ(LIBC_NAMESPACE::pthread_mutex_lock(&recursive_mutex), 0);
 
   pthread_t thread;
-  ASSERT_EQ(LIBC_NAMESPACE::pthread_create(&thread, nullptr, trylock_other_thread,
-                                           &recursive_mutex),
+  ASSERT_EQ(LIBC_NAMESPACE::pthread_create(
+                &thread, nullptr, trylock_other_thread, &recursive_mutex),
             0);
   void *retval = nullptr;
   ASSERT_EQ(LIBC_NAMESPACE::pthread_join(thread, &retval), 0);
diff --git a/libc/test/integration/src/threads/mtx_test.cpp b/libc/test/integration/src/threads/mtx_test.cpp
index 5aa2d6d1b..909c4f2c5 100644
--- a/libc/test/integration/src/threads/mtx_test.cpp
+++ b/libc/test/integration/src/threads/mtx_test.cpp
@@ -6,13 +6,13 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "src/string/memory_utils/inline_memcpy.h"
 #include "src/threads/mtx_destroy.h"
 #include "src/threads/mtx_init.h"
 #include "src/threads/mtx_lock.h"
 #include "src/threads/mtx_unlock.h"
 #include "src/threads/thrd_create.h"
 #include "src/threads/thrd_join.h"
-#include "src/string/memory_utils/inline_memcpy.h"
 
 #include "test/IntegrationTest/test.h"
 

``````````

</details>


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


More information about the libc-commits mailing list