summaryrefslogtreecommitdiff
path: root/src/cxa_thread_atexit.cpp
diff options
context:
space:
mode:
authorAsiri Rathnayake <asiri.rathnayake@arm.com>2016-10-13 15:05:19 +0000
committerAsiri Rathnayake <asiri.rathnayake@arm.com>2016-10-13 15:05:19 +0000
commit5180673e0abca22cdc611dc869caf82ae728f3d3 (patch)
treef2507c7ac8f13bd632dd1ef31dbd3df9b574669d /src/cxa_thread_atexit.cpp
parent3f7b3700184b818c28ee085e3d629aa5f314169b (diff)
[libcxxabi] Refactor pthread usage into a separate API
This patch refactors all pthread uses of libc++abi into a separate API. This is the first step towards supporting an externlly-threaded libc++abi library. I've followed the conventions already used in the libc++ library for the same purpose. Patch from: Saleem Abdulrasool and Asiri Rathnayake Reviewed by: compnerd, EricWF Differential revisions: https://reviews.llvm.org/D18482 (original) https://reviews.llvm.org/D24864 (final) git-svn-id: https://llvm.org/svn/llvm-project/libcxxabi/trunk@284128 91177308-0d34-0410-b5e6-96231b3b80d8
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;