am c3307dc4
: Merge "Better control of pthread keys used in bionic."
* commit 'c3307dc43b2526c4031837738b139d22831c5d09': Better control of pthread keys used in bionic.
This commit is contained in:
commit
9ecb7f40d0
@ -36,6 +36,7 @@
|
||||
#include <wchar.h>
|
||||
|
||||
#include "private/bionic_macros.h"
|
||||
#include "private/ThreadLocalBuffer.h"
|
||||
|
||||
// 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;
|
||||
|
||||
// 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;
|
||||
__attribute__((constructor)) static void __bionic_tls_uselocale_key_init() {
|
||||
pthread_key_create(&g_uselocale_key, NULL);
|
||||
}
|
||||
BIONIC_PTHREAD_KEY_WITH_CONSTRUCTOR(g_uselocale_key, NULL);
|
||||
|
||||
static void __locale_init() {
|
||||
g_locale.decimal_point = const_cast<char*>(".");
|
||||
|
@ -39,6 +39,8 @@
|
||||
#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
|
||||
#include <sys/_system_properties.h>
|
||||
|
||||
#include "private/ThreadLocalBuffer.h"
|
||||
|
||||
/* Set to 1 to enable debug traces */
|
||||
#define DEBUG 0
|
||||
|
||||
@ -50,8 +52,6 @@
|
||||
# define D(...) do{}while(0)
|
||||
#endif
|
||||
|
||||
static pthread_key_t _res_key;
|
||||
|
||||
typedef struct {
|
||||
int _h_errno;
|
||||
// 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);
|
||||
}
|
||||
|
||||
__attribute__((constructor))
|
||||
static void
|
||||
_res_init_key( void )
|
||||
{
|
||||
pthread_key_create( &_res_key, _res_thread_free );
|
||||
}
|
||||
BIONIC_PTHREAD_KEY_WITH_CONSTRUCTOR(_res_key, _res_thread_free);
|
||||
|
||||
static _res_thread*
|
||||
_res_thread_get(void)
|
||||
|
@ -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) \
|
||||
|
@ -78,7 +78,7 @@ enum {
|
||||
* Following are current pthread keys used internally by libc:
|
||||
* basename 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_strings 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)
|
||||
* passwd 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
|
||||
|
Loading…
Reference in New Issue
Block a user