提交 c9806fc2 编写于 作者: R Rich Felker

greatly simplify pthread_key_create (~20% size reduction)

上级 a5323c57
......@@ -9,18 +9,17 @@ static void nodtor(void *dummy)
int pthread_key_create(pthread_key_t *k, void (*dtor)(void *))
{
static void (*keys[PTHREAD_KEYS_MAX])(void *);
int i = (uintptr_t)&k / 16 % PTHREAD_KEYS_MAX;
int j = i;
unsigned i = (uintptr_t)&k / 16 % PTHREAD_KEYS_MAX;
unsigned j = i;
pthread_self();
libc.tsd_keys = keys;
if (!dtor) dtor = nodtor;
/* Cheap trick - &k cannot match any destructor pointer */
while (a_cas_p(keys+j, 0, &k)
&& (j=(j+1)%PTHREAD_KEYS_MAX) != i);
if (keys[j] != (void (*)(void *))&k)
return EAGAIN;
keys[j] = dtor;
*k = j;
return 0;
do {
if (!a_cas_p(keys+j, 0, dtor)) {
*k = j;
return 0;
}
} while ((j=(j+1)%PTHREAD_KEYS_MAX) != i);
return EAGAIN;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册