Merge "Don\'t use __thread in __cxa_thread_finalize()."
am: 28d3f00cf4 * commit '28d3f00cf4545812503c835ea906fa83309e48ed': Don't use __thread in __cxa_thread_finalize().
This commit is contained in:
commit
51ca18d2a1
@ -15,6 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
|
|
||||||
|
#include "pthread_internal.h"
|
||||||
|
|
||||||
struct thread_local_dtor {
|
struct thread_local_dtor {
|
||||||
void (*func) (void *);
|
void (*func) (void *);
|
||||||
void *arg;
|
void *arg;
|
||||||
@ -22,25 +24,24 @@ struct thread_local_dtor {
|
|||||||
thread_local_dtor* next;
|
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) {
|
extern "C" int __cxa_thread_atexit_impl(void (*func) (void *), void *arg, void *dso_handle) {
|
||||||
thread_local_dtor* dtor = new thread_local_dtor();
|
thread_local_dtor* dtor = new thread_local_dtor();
|
||||||
|
|
||||||
dtor->func = func;
|
dtor->func = func;
|
||||||
dtor->arg = arg;
|
dtor->arg = arg;
|
||||||
dtor->dso_handle = dso_handle;
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" __LIBC_HIDDEN__ void __cxa_thread_finalize() {
|
extern "C" __LIBC_HIDDEN__ void __cxa_thread_finalize() {
|
||||||
while (thread_local_dtors != nullptr) {
|
pthread_internal_t* thread = __get_thread();
|
||||||
thread_local_dtor* current = thread_local_dtors;
|
while (thread->thread_local_dtors != nullptr) {
|
||||||
thread_local_dtors = current->next;
|
thread_local_dtor* current = thread->thread_local_dtors;
|
||||||
|
thread->thread_local_dtors = current->next;
|
||||||
|
|
||||||
current->func(current->arg);
|
current->func(current->arg);
|
||||||
delete current;
|
delete current;
|
||||||
|
@ -52,6 +52,8 @@ enum ThreadJoinState {
|
|||||||
THREAD_DETACHED
|
THREAD_DETACHED
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct thread_local_dtor;
|
||||||
|
|
||||||
struct pthread_internal_t {
|
struct pthread_internal_t {
|
||||||
struct pthread_internal_t* next;
|
struct pthread_internal_t* next;
|
||||||
struct pthread_internal_t* prev;
|
struct pthread_internal_t* prev;
|
||||||
@ -94,6 +96,8 @@ struct pthread_internal_t {
|
|||||||
|
|
||||||
size_t mmap_size;
|
size_t mmap_size;
|
||||||
|
|
||||||
|
thread_local_dtor* thread_local_dtors;
|
||||||
|
|
||||||
void* tls[BIONIC_TLS_SLOTS];
|
void* tls[BIONIC_TLS_SLOTS];
|
||||||
|
|
||||||
pthread_key_data_t key_data[BIONIC_PTHREAD_KEY_COUNT];
|
pthread_key_data_t key_data[BIONIC_PTHREAD_KEY_COUNT];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user