summaryrefslogtreecommitdiff
path: root/lib/libpthread/pthread_tsd.c
diff options
context:
space:
mode:
authorad <ad@NetBSD.org>2008-03-07 22:27:07 +0000
committerad <ad@NetBSD.org>2008-03-07 22:27:07 +0000
commit55faac1242df104b8948931d28bad94bbb4c69ef (patch)
treee942751b4c46c328151882c277973c655fc7f865 /lib/libpthread/pthread_tsd.c
parent8548e338865f2cc902e97c18d347078321e5f1ee (diff)
pthread_key_create: instead of using a simple 1/0 value to record a key
as allocated, use an array of pointers and save __builtin_return_address(0) so keys can be identified when doing post-mortem debugging.
Diffstat (limited to 'lib/libpthread/pthread_tsd.c')
-rw-r--r--lib/libpthread/pthread_tsd.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/lib/libpthread/pthread_tsd.c b/lib/libpthread/pthread_tsd.c
index 14ef65f5a83..8a48df12813 100644
--- a/lib/libpthread/pthread_tsd.c
+++ b/lib/libpthread/pthread_tsd.c
@@ -1,4 +1,4 @@
-/* $NetBSD: pthread_tsd.c,v 1.4 2007/12/24 14:46:29 ad Exp $ */
+/* $NetBSD: pthread_tsd.c,v 1.5 2008/03/07 22:27:07 ad Exp $ */
/*-
* Copyright (c) 2001, 2007 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: pthread_tsd.c,v 1.4 2007/12/24 14:46:29 ad Exp $");
+__RCSID("$NetBSD: pthread_tsd.c,v 1.5 2008/03/07 22:27:07 ad Exp $");
/* Functions and structures dealing with thread-specific data */
#include <errno.h>
@@ -47,7 +47,7 @@ __RCSID("$NetBSD: pthread_tsd.c,v 1.4 2007/12/24 14:46:29 ad Exp $");
static pthread_mutex_t tsd_mutex = PTHREAD_MUTEX_INITIALIZER;
static int nextkey;
-int pthread__tsd_alloc[PTHREAD_KEYS_MAX];
+void *pthread__tsd_alloc[PTHREAD_KEYS_MAX];
void (*pthread__tsd_destructors[PTHREAD_KEYS_MAX])(void *);
__strong_alias(__libc_thr_keycreate,pthread_key_create)
@@ -64,7 +64,7 @@ pthread_key_create(pthread_key_t *key, void (*destructor)(void *))
/* Find an available slot */
/* 1. Search from "nextkey" to the end of the list. */
for (i = nextkey; i < PTHREAD_KEYS_MAX; i++)
- if (pthread__tsd_alloc[i] == 0)
+ if (pthread__tsd_alloc[i] == NULL)
break;
if (i == PTHREAD_KEYS_MAX) {
@@ -72,7 +72,7 @@ pthread_key_create(pthread_key_t *key, void (*destructor)(void *))
* of the list back to "nextkey".
*/
for (i = 0; i < nextkey; i++)
- if (pthread__tsd_alloc[i] == 0)
+ if (pthread__tsd_alloc[i] == NULL)
break;
if (i == nextkey) {
@@ -85,7 +85,7 @@ pthread_key_create(pthread_key_t *key, void (*destructor)(void *))
}
/* Got one. */
- pthread__tsd_alloc[i] = 1;
+ pthread__tsd_alloc[i] = __builtin_return_address(0);
nextkey = (i + 1) % PTHREAD_KEYS_MAX;
pthread__tsd_destructors[i] = destructor;
pthread_mutex_unlock(&tsd_mutex);