greatly simplify pthread_key_create (~20% size reduction)
This commit is contained in:
parent
a5323c5768
commit
c9806fc2f9
1 changed files with 9 additions and 10 deletions
|
|
@ -9,18 +9,17 @@ static void nodtor(void *dummy)
|
||||||
int pthread_key_create(pthread_key_t *k, void (*dtor)(void *))
|
int pthread_key_create(pthread_key_t *k, void (*dtor)(void *))
|
||||||
{
|
{
|
||||||
static void (*keys[PTHREAD_KEYS_MAX])(void *);
|
static void (*keys[PTHREAD_KEYS_MAX])(void *);
|
||||||
int i = (uintptr_t)&k / 16 % PTHREAD_KEYS_MAX;
|
unsigned i = (uintptr_t)&k / 16 % PTHREAD_KEYS_MAX;
|
||||||
int j = i;
|
unsigned j = i;
|
||||||
|
|
||||||
pthread_self();
|
pthread_self();
|
||||||
libc.tsd_keys = keys;
|
libc.tsd_keys = keys;
|
||||||
if (!dtor) dtor = nodtor;
|
if (!dtor) dtor = nodtor;
|
||||||
/* Cheap trick - &k cannot match any destructor pointer */
|
do {
|
||||||
while (a_cas_p(keys+j, 0, &k)
|
if (!a_cas_p(keys+j, 0, dtor)) {
|
||||||
&& (j=(j+1)%PTHREAD_KEYS_MAX) != i);
|
*k = j;
|
||||||
if (keys[j] != (void (*)(void *))&k)
|
return 0;
|
||||||
return EAGAIN;
|
}
|
||||||
keys[j] = dtor;
|
} while ((j=(j+1)%PTHREAD_KEYS_MAX) != i);
|
||||||
*k = j;
|
return EAGAIN;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue