[libc-commits] [PATCH] D121334: [libc] Use the constexpr constructor to initialize exit handlers mutex.

Siva Chandra via Phabricator via libc-commits libc-commits at lists.llvm.org
Wed Mar 9 18:52:44 PST 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rG83b8878fbb0e: [libc] Use the constexpr constructor to initialize exit handlers mutex. (authored by sivachandra).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121334/new/

https://reviews.llvm.org/D121334

Files:
  libc/src/stdlib/CMakeLists.txt
  libc/src/stdlib/atexit.cpp


Index: libc/src/stdlib/atexit.cpp
===================================================================
--- libc/src/stdlib/atexit.cpp
+++ libc/src/stdlib/atexit.cpp
@@ -9,20 +9,13 @@
 #include "src/stdlib/atexit.h"
 #include "src/__support/CPP/vector.h"
 #include "src/__support/common.h"
-#include "src/threads/mtx_init.h"
-#include "src/threads/mtx_lock.h"
-#include "src/threads/mtx_unlock.h"
+#include "src/__support/threads/mutex.h"
 
 namespace __llvm_libc {
 
 namespace {
 
-mtx_t lock;
-// TODO need an easier way to use mtx_t internally, or use pthread_mutex_t
-// with PTHREAD_MUTEX_INITIALIZER when it lands.
-struct Init {
-  Init() { __llvm_libc::mtx_init(&lock, mtx_plain); }
-} init;
+Mutex handler_list_mtx(false, false, false);
 
 // TOOD should we make cpp::vector like llvm::SmallVector<T, N> where it will
 // allocate at least N before needing dynamic allocation?
@@ -33,21 +26,21 @@
 namespace internal {
 
 void call_exit_handlers() {
-  __llvm_libc::mtx_lock(&lock);
+  handler_list_mtx.lock();
   // TODO: implement rbegin() + rend() for cpp::vector
   for (int i = handlers.size() - 1; i >= 0; i--) {
-    __llvm_libc::mtx_unlock(&lock);
+    handler_list_mtx.unlock();
     handlers[i]();
-    __llvm_libc::mtx_lock(&lock);
+    handler_list_mtx.lock();
   }
 }
 
 } // namespace internal
 
 LLVM_LIBC_FUNCTION(int, atexit, (void (*function)())) {
-  __llvm_libc::mtx_lock(&lock);
+  handler_list_mtx.lock();
   handlers.push_back(function);
-  __llvm_libc::mtx_unlock(&lock);
+  handler_list_mtx.unlock();
   return 0;
 }
 
Index: libc/src/stdlib/CMakeLists.txt
===================================================================
--- libc/src/stdlib/CMakeLists.txt
+++ libc/src/stdlib/CMakeLists.txt
@@ -278,9 +278,7 @@
     atexit.h
   DEPENDS
     libc.src.__support.CPP.vector
-    libc.src.threads.mtx_init
-    libc.src.threads.mtx_lock
-    libc.src.threads.mtx_unlock
+    libc.src.__support.threads.thread
 )
 
 add_entrypoint_object(


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D121334.414264.patch
Type: text/x-patch
Size: 1971 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20220310/58fdf2de/attachment.bin>


More information about the libc-commits mailing list