#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").
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*>(".");
#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
# 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.
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)
// 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) \
* 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)
* 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