Better control of pthread keys used in bionic.
Change-Id: I1e1bc77c0e7879baead6c3417282ce549a1153b5
This commit is contained in:
parent
dec9501af2
commit
4a2891d8c8
@ -36,6 +36,7 @@
|
|||||||
#include <wchar.h>
|
#include <wchar.h>
|
||||||
|
|
||||||
#include "private/bionic_macros.h"
|
#include "private/bionic_macros.h"
|
||||||
|
#include "private/ThreadLocalBuffer.h"
|
||||||
|
|
||||||
// We currently support a single locale, the "C" locale (also known as "POSIX").
|
// We currently support a single locale, the "C" locale (also known as "POSIX").
|
||||||
|
|
||||||
@ -62,10 +63,7 @@ static pthread_once_t g_locale_once = PTHREAD_ONCE_INIT;
|
|||||||
static lconv g_locale;
|
static lconv g_locale;
|
||||||
|
|
||||||
// We don't use pthread_once for this so that we know when the resource (a TLS slot) will be taken.
|
// We don't use pthread_once for this so that we know when the resource (a TLS slot) will be taken.
|
||||||
static pthread_key_t g_uselocale_key;
|
BIONIC_PTHREAD_KEY_WITH_CONSTRUCTOR(g_uselocale_key, NULL);
|
||||||
__attribute__((constructor)) static void __bionic_tls_uselocale_key_init() {
|
|
||||||
pthread_key_create(&g_uselocale_key, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void __locale_init() {
|
static void __locale_init() {
|
||||||
g_locale.decimal_point = const_cast<char*>(".");
|
g_locale.decimal_point = const_cast<char*>(".");
|
||||||
|
@ -39,6 +39,8 @@
|
|||||||
#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
|
#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
|
||||||
#include <sys/_system_properties.h>
|
#include <sys/_system_properties.h>
|
||||||
|
|
||||||
|
#include "private/ThreadLocalBuffer.h"
|
||||||
|
|
||||||
/* Set to 1 to enable debug traces */
|
/* Set to 1 to enable debug traces */
|
||||||
#define DEBUG 0
|
#define DEBUG 0
|
||||||
|
|
||||||
@ -50,8 +52,6 @@
|
|||||||
# define D(...) do{}while(0)
|
# define D(...) do{}while(0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static pthread_key_t _res_key;
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int _h_errno;
|
int _h_errno;
|
||||||
// TODO: Have one __res_state per network so we don't have to repopulate frequently.
|
// TODO: Have one __res_state per network so we don't have to repopulate frequently.
|
||||||
@ -105,12 +105,7 @@ _res_thread_free( void* _rt )
|
|||||||
free(rt);
|
free(rt);
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((constructor))
|
BIONIC_PTHREAD_KEY_WITH_CONSTRUCTOR(_res_key, _res_thread_free);
|
||||||
static void
|
|
||||||
_res_init_key( void )
|
|
||||||
{
|
|
||||||
pthread_key_create( &_res_key, _res_thread_free );
|
|
||||||
}
|
|
||||||
|
|
||||||
static _res_thread*
|
static _res_thread*
|
||||||
_res_thread_get(void)
|
_res_thread_get(void)
|
||||||
|
@ -38,15 +38,17 @@
|
|||||||
|
|
||||||
// We used to use pthread_once to initialize the keys, but life is more predictable
|
// 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__.
|
// 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) \
|
#define GLOBAL_INIT_THREAD_LOCAL_BUFFER(name) \
|
||||||
static pthread_key_t __bionic_tls_ ## name ## _key; \
|
|
||||||
static void __bionic_tls_ ## name ## _key_destroy(void* buffer) { \
|
static void __bionic_tls_ ## name ## _key_destroy(void* buffer) { \
|
||||||
free(buffer); \
|
free(buffer); \
|
||||||
} \
|
} \
|
||||||
__attribute__((constructor)) static void __bionic_tls_ ## name ## _key_init() { \
|
BIONIC_PTHREAD_KEY_WITH_CONSTRUCTOR(__bionic_tls_ ## name ## _key, __bionic_tls_ ## name ## _key_destroy)
|
||||||
pthread_key_create(&__bionic_tls_ ## name ## _key, __bionic_tls_ ## name ## _key_destroy); \
|
|
||||||
}
|
|
||||||
|
|
||||||
// Leaves "name_tls_buffer" and "name_tls_buffer_size" defined and initialized.
|
// Leaves "name_tls_buffer" and "name_tls_buffer_size" defined and initialized.
|
||||||
#define LOCAL_INIT_THREAD_LOCAL_BUFFER(type, name, byte_count) \
|
#define LOCAL_INIT_THREAD_LOCAL_BUFFER(type, name, byte_count) \
|
||||||
|
@ -78,7 +78,7 @@ enum {
|
|||||||
* Following are current pthread keys used internally by libc:
|
* Following are current pthread keys used internally by libc:
|
||||||
* basename libc (GLOBAL_INIT_THREAD_LOCAL_BUFFER)
|
* basename libc (GLOBAL_INIT_THREAD_LOCAL_BUFFER)
|
||||||
* dirname libc (GLOBAL_INIT_THREAD_LOCAL_BUFFER)
|
* dirname libc (GLOBAL_INIT_THREAD_LOCAL_BUFFER)
|
||||||
* uselocale libc
|
* uselocale libc (BIONIC_PTHREAD_KEY_WITH_CONSTRUCTOR)
|
||||||
* getmntent_mntent libc (GLOBAL_INIT_THREAD_LOCAL_BUFFER)
|
* getmntent_mntent libc (GLOBAL_INIT_THREAD_LOCAL_BUFFER)
|
||||||
* getmntent_strings libc (GLOBAL_INIT_THREAD_LOCAL_BUFFER)
|
* getmntent_strings libc (GLOBAL_INIT_THREAD_LOCAL_BUFFER)
|
||||||
* ptsname libc (GLOBAL_INIT_THREAD_LOCAL_BUFFER)
|
* ptsname libc (GLOBAL_INIT_THREAD_LOCAL_BUFFER)
|
||||||
@ -87,7 +87,7 @@ enum {
|
|||||||
* strsignal libc (GLOBAL_INIT_THREAD_LOCAL_BUFFER)
|
* strsignal libc (GLOBAL_INIT_THREAD_LOCAL_BUFFER)
|
||||||
* passwd libc (GLOBAL_INIT_THREAD_LOCAL_BUFFER)
|
* passwd libc (GLOBAL_INIT_THREAD_LOCAL_BUFFER)
|
||||||
* group libc (GLOBAL_INIT_THREAD_LOCAL_BUFFER)
|
* group libc (GLOBAL_INIT_THREAD_LOCAL_BUFFER)
|
||||||
* _res_key libc
|
* _res_key libc (BIONIC_PTHREAD_KEY_WITH_CONSTRUCTOR)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define LIBC_PTHREAD_KEY_RESERVED_COUNT 12
|
#define LIBC_PTHREAD_KEY_RESERVED_COUNT 12
|
||||||
|
Loading…
Reference in New Issue
Block a user