aboutsummaryrefslogtreecommitdiff
path: root/sysdeps/htl/pt-setspecific.c
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps/htl/pt-setspecific.c')
-rw-r--r--sysdeps/htl/pt-setspecific.c26
1 files changed, 24 insertions, 2 deletions
diff --git a/sysdeps/htl/pt-setspecific.c b/sysdeps/htl/pt-setspecific.c
index 2b9a89d..30550e0 100644
--- a/sysdeps/htl/pt-setspecific.c
+++ b/sysdeps/htl/pt-setspecific.c
@@ -28,12 +28,34 @@ __pthread_setspecific (pthread_key_t key, const void *value)
if (key < 0 || key >= __pthread_key_count)
return EINVAL;
+ if (self->thread_specifics == NULL)
+ {
+ if (key < PTHREAD_STATIC_KEYS)
+ {
+ self->static_thread_specifics[key] = (void *) value;
+ return 0;
+ }
+ }
+
if (key >= self->thread_specifics_size)
{
/* Amortize reallocation cost. */
int newsize = 2 * key + 1;
- void **new = realloc (self->thread_specifics,
- newsize * sizeof (new[0]));
+ void **new;
+
+ if (self->thread_specifics == NULL)
+ {
+ self->thread_specifics_size = PTHREAD_STATIC_KEYS;
+ new = malloc (newsize * sizeof (new[0]));
+ if (new != NULL)
+ memcpy (new, self->static_thread_specifics,
+ PTHREAD_STATIC_KEYS * sizeof (new[0]));
+ }
+ else
+ {
+ new = realloc (self->thread_specifics,
+ newsize * sizeof (new[0]));
+ }
if (new == NULL)
return ENOMEM;