Better control of pthread keys used in bionic.

Change-Id: I1e1bc77c0e7879baead6c3417282ce549a1153b5
This commit is contained in:
Yabin Cui
2015-03-04 16:53:23 -08:00
parent dec9501af2
commit 4a2891d8c8
4 changed files with 13 additions and 18 deletions

View File

@@ -38,15 +38,17 @@
// We used to use pthread_once to initialize the keys, but life is more predictable
// if we allocate them all up front when the C library starts up, via __constructor__.
#define BIONIC_PTHREAD_KEY_WITH_CONSTRUCTOR(key_name, key_destructor) \
static pthread_key_t key_name; \
__attribute__((constructor)) static void __bionic_tls_ ## key_name ## _key_init() { \
pthread_key_create(&key_name, key_destructor); \
}
#define GLOBAL_INIT_THREAD_LOCAL_BUFFER(name) \
static pthread_key_t __bionic_tls_ ## name ## _key; \
static void __bionic_tls_ ## name ## _key_destroy(void* buffer) { \
free(buffer); \
} \
__attribute__((constructor)) static void __bionic_tls_ ## name ## _key_init() { \
pthread_key_create(&__bionic_tls_ ## name ## _key, __bionic_tls_ ## name ## _key_destroy); \
}
BIONIC_PTHREAD_KEY_WITH_CONSTRUCTOR(__bionic_tls_ ## name ## _key, __bionic_tls_ ## name ## _key_destroy)
// Leaves "name_tls_buffer" and "name_tls_buffer_size" defined and initialized.
#define LOCAL_INIT_THREAD_LOCAL_BUFFER(type, name, byte_count) \