diff options
author | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2023-08-08 12:10:06 +0200 |
---|---|---|
committer | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2023-08-08 12:17:48 +0200 |
commit | 644aa127b9b42a899a12b6ccc6644bc035c231e3 (patch) | |
tree | 46590a3c1c485dc2f423ded55671f4cb56bed532 /sysdeps/htl/pt-key-create.c | |
parent | dcad5c8578130dec7f35fd5b0885304b59f9f543 (diff) | |
download | glibc-644aa127b9b42a899a12b6ccc6644bc035c231e3.tar.gz glibc-644aa127b9b42a899a12b6ccc6644bc035c231e3.tar.xz glibc-644aa127b9b42a899a12b6ccc6644bc035c231e3.zip |
htl: Add support for static TSD data
When using jemalloc, malloc() needs to use TSD, while libpthread initialization needs malloc(). Supporting a static TSD area allows jemalloc and libpthread to initialize together.
Diffstat (limited to 'sysdeps/htl/pt-key-create.c')
-rw-r--r-- | sysdeps/htl/pt-key-create.c | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/sysdeps/htl/pt-key-create.c b/sysdeps/htl/pt-key-create.c index 51c0ef72b8..b7057434e3 100644 --- a/sysdeps/htl/pt-key-create.c +++ b/sysdeps/htl/pt-key-create.c @@ -26,10 +26,11 @@ pthread_mutex_t __pthread_key_lock; pthread_once_t __pthread_key_once = PTHREAD_ONCE_INIT; -void (**__pthread_key_destructors) (void *arg); -int __pthread_key_size; +void (*__pthread_static_key_destructors [PTHREAD_STATIC_KEYS]) (void *arg); +void (**__pthread_key_destructors) (void *arg) = __pthread_static_key_destructors; +int __pthread_key_size = PTHREAD_STATIC_KEYS; int __pthread_key_count; -int __pthread_key_invalid_count; +int __pthread_key_invalid_count = PTHREAD_STATIC_KEYS; int __pthread_key_create (pthread_key_t *key, void (*destructor) (void *)) @@ -80,13 +81,21 @@ do_search: void *t; int newsize; - if (__pthread_key_size == 0) - newsize = 8; + newsize = __pthread_key_size * 2; + + if (__pthread_key_destructors == __pthread_static_key_destructors) + { + /* We were still using the static array. Switch to dynamic. */ + t = malloc (newsize * sizeof (*__pthread_key_destructors)); + + if (t != NULL) + memcpy (t, __pthread_key_destructors, + __pthread_key_size * sizeof (*__pthread_key_destructors)); + } else - newsize = __pthread_key_size * 2; + t = realloc (__pthread_key_destructors, + newsize * sizeof (*__pthread_key_destructors)); - t = realloc (__pthread_key_destructors, - newsize * sizeof (*__pthread_key_destructors)); if (t == NULL) { __pthread_mutex_unlock (&__pthread_key_lock); |