Merge "Don't use __thread in __cxa_thread_finalize()."

This commit is contained in:
Yabin Cui 2015-11-30 21:59:47 +00:00 committed by Gerrit Code Review
commit 28d3f00cf4
2 changed files with 13 additions and 8 deletions

View File

@ -15,6 +15,8 @@
*/
#include <sys/cdefs.h>
#include "pthread_internal.h"
struct thread_local_dtor {
void (*func) (void *);
void *arg;
@ -22,25 +24,24 @@ struct thread_local_dtor {
thread_local_dtor* next;
};
static __thread thread_local_dtor* thread_local_dtors = nullptr;
extern "C" int __cxa_thread_atexit_impl(void (*func) (void *), void *arg, void *dso_handle) {
thread_local_dtor* dtor = new thread_local_dtor();
dtor->func = func;
dtor->arg = arg;
dtor->dso_handle = dso_handle;
dtor->next = thread_local_dtors;
thread_local_dtors = dtor;
pthread_internal_t* thread = __get_thread();
dtor->next = thread->thread_local_dtors;
thread->thread_local_dtors = dtor;
return 0;
}
extern "C" __LIBC_HIDDEN__ void __cxa_thread_finalize() {
while (thread_local_dtors != nullptr) {
thread_local_dtor* current = thread_local_dtors;
thread_local_dtors = current->next;
pthread_internal_t* thread = __get_thread();
while (thread->thread_local_dtors != nullptr) {
thread_local_dtor* current = thread->thread_local_dtors;
thread->thread_local_dtors = current->next;
current->func(current->arg);
delete current;

View File

@ -52,6 +52,8 @@ enum ThreadJoinState {
THREAD_DETACHED
};
struct thread_local_dtor;
struct pthread_internal_t {
struct pthread_internal_t* next;
struct pthread_internal_t* prev;
@ -94,6 +96,8 @@ struct pthread_internal_t {
size_t mmap_size;
thread_local_dtor* thread_local_dtors;
void* tls[BIONIC_TLS_SLOTS];
pthread_key_data_t key_data[BIONIC_PTHREAD_KEY_COUNT];