summaryrefslogtreecommitdiff
path: root/src/cxa_thread_atexit.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/cxa_thread_atexit.cpp')
-rw-r--r--src/cxa_thread_atexit.cpp25
1 files changed, 13 insertions, 12 deletions
diff --git a/src/cxa_thread_atexit.cpp b/src/cxa_thread_atexit.cpp
index dea5c21..933c9c7 100644
--- a/src/cxa_thread_atexit.cpp
+++ b/src/cxa_thread_atexit.cpp
@@ -9,8 +9,8 @@
#include "abort_message.h"
#include "cxxabi.h"
+#include "threading_support.h"
#include <cstdlib>
-#include <pthread.h>
namespace __cxxabiv1 {
@@ -39,9 +39,10 @@ namespace {
// destructors of any objects with static storage duration.
//
// - thread_local destructors on non-main threads run on the first iteration
- // through the pthread_key destructors. std::notify_all_at_thread_exit()
- // and similar functions must be careful to wait until the second iteration
- // to provide their intended ordering guarantees.
+ // through the __libcxxabi_tls_key destructors.
+ // std::notify_all_at_thread_exit() and similar functions must be careful to
+ // wait until the second iteration to provide their intended ordering
+ // guarantees.
//
// Another limitation, though one shared with ..._impl(), is that any
// thread_locals that are first initialized after non-thread_local global
@@ -65,7 +66,7 @@ namespace {
// True if the destructors are currently scheduled to run on this thread
__thread bool dtors_alive = false;
// Used to trigger destructors on thread exit; value is ignored
- pthread_key_t dtors_key;
+ __libcxxabi_tls_key dtors_key;
void run_dtors(void*) {
while (auto head = dtors) {
@@ -79,16 +80,16 @@ namespace {
struct DtorsManager {
DtorsManager() {
- // There is intentionally no matching pthread_key_delete call, as
+ // There is intentionally no matching __libcxxabi_tls_delete call, as
// __cxa_thread_atexit() may be called arbitrarily late (for example, from
// global destructors or atexit() handlers).
- if (pthread_key_create(&dtors_key, run_dtors) != 0) {
- abort_message("pthread_key_create() failed in __cxa_thread_atexit()");
+ if (__libcxxabi_tls_create(&dtors_key, run_dtors) != 0) {
+ abort_message("__libcxxabi_tls_create() failed in __cxa_thread_atexit()");
}
}
~DtorsManager() {
- // pthread_key destructors do not run on threads that call exit()
+ // __libcxxabi_tls_key destructors do not run on threads that call exit()
// (including when the main thread returns from main()), so we explicitly
// call the destructor here. This runs at exit time (potentially earlier
// if libc++abi is dlclose()'d). Any thread_locals initialized after this
@@ -109,12 +110,12 @@ extern "C" {
if (__cxa_thread_atexit_impl) {
return __cxa_thread_atexit_impl(dtor, obj, dso_symbol);
} else {
- // Initialize the dtors pthread_key (uses __cxa_guard_*() for one-time
- // initialization and __cxa_atexit() for destruction)
+ // Initialize the dtors __libcxxabi_tls_key (uses __cxa_guard_*() for
+ // one-time initialization and __cxa_atexit() for destruction)
static DtorsManager manager;
if (!dtors_alive) {
- if (pthread_setspecific(dtors_key, &dtors_key) != 0) {
+ if (__libcxxabi_tls_set(dtors_key, &dtors_key) != 0) {
return -1;
}
dtors_alive = true;