[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 13:53:41 PST 2022
sivachandra created this revision.
sivachandra added reviewers: abrachet, lntue, michaelrj.
Herald added subscribers: libc-commits, ecnelises, tschuett, mgorny.
Herald added projects: libc-project, All.
sivachandra requested review of this revision.
To actually get the benifit of the constexpr construction and destruction
of the mutex, the optimization level for atexit has been raised to O3 <https://reviews.llvm.org/owners/package/3/>.
Repository:
rG LLVM Github Monorepo
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
@@ -276,11 +276,11 @@
atexit.cpp
HDRS
atexit.h
+ COMPILE_OPTIONS
+ -O3
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.414208.patch
Type: text/x-patch
Size: 2025 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20220309/41978137/attachment.bin>
More information about the libc-commits
mailing list