Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/llvm/llvm-project.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAsiri Rathnayake <asiri.rathnayake@arm.com>2016-10-13 18:05:19 +0300
committerAsiri Rathnayake <asiri.rathnayake@arm.com>2016-10-13 18:05:19 +0300
commit6d3ea6831d6fe30683d6b5078ad826fdedc2e946 (patch)
tree92f3fb6daa13e34459ba54f27f5bad8da3099793 /libcxxabi/src/cxa_thread_atexit.cpp
parent85874a9360334ddb9619aca6344b8ee53296fa1e (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) llvm-svn: 284128
Diffstat (limited to 'libcxxabi/src/cxa_thread_atexit.cpp')
-rw-r--r--libcxxabi/src/cxa_thread_atexit.cpp25
1 files changed, 13 insertions, 12 deletions
diff --git a/libcxxabi/src/cxa_thread_atexit.cpp b/libcxxabi/src/cxa_thread_atexit.cpp
index dea5c21504b2..933c9c7243c0 100644
--- a/libcxxabi/src/cxa_thread_atexit.cpp
+++ b/libcxxabi/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;