diff options
| author | nathanw <nathanw@NetBSD.org> | 2003-01-21 23:29:22 +0000 |
|---|---|---|
| committer | nathanw <nathanw@NetBSD.org> | 2003-01-21 23:29:22 +0000 |
| commit | dc651e62dfb3627eb95f982adfae545d2c828a26 (patch) | |
| tree | 406953fd9b4da50e3760cc5ec15cbcfc54dcfa98 /lib/libpthread | |
| parent | 6003a24dd4f8c1c10326b22ff83dfbeba09d7101 (diff) | |
Don't bother acquiring the tsd_lock and reading the destructor function
if the corresponding TSD entry is empty.
Cuts down lock/unlock pairs for this operation from 256 to the number
of active TSD entries; sicne this is done when every thread exits, it saves
many total lock/unlock pairs.
Diffstat (limited to 'lib/libpthread')
| -rw-r--r-- | lib/libpthread/pthread_specific.c | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/lib/libpthread/pthread_specific.c b/lib/libpthread/pthread_specific.c index e95aa5e37a8..8ed1fc26d04 100644 --- a/lib/libpthread/pthread_specific.c +++ b/lib/libpthread/pthread_specific.c @@ -1,4 +1,4 @@ -/* $NetBSD: pthread_specific.c,v 1.3 2003/01/18 18:45:57 christos Exp $ */ +/* $NetBSD: pthread_specific.c,v 1.4 2003/01/21 23:29:22 nathanw Exp $ */ /*- * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -243,15 +243,16 @@ pthread__destroy_tsd(pthread_t self) do { done = 1; for (i = 0; i < PTHREAD_KEYS_MAX; i++) { - pthread_mutex_lock(&tsd_mutex); - destructor = pthread__tsd_destructors[i]; - pthread_mutex_unlock(&tsd_mutex); - if ((self->pt_specific[i] != NULL) && - destructor != NULL) { - done = 0; - val = self->pt_specific[i]; - self->pt_specific[i] = NULL; /* see above */ - (*destructor)(val); + if (self->pt_specific[i] != NULL) { + pthread_mutex_lock(&tsd_mutex); + destructor = pthread__tsd_destructors[i]; + pthread_mutex_unlock(&tsd_mutex); + if (destructor != NULL) { + done = 0; + val = self->pt_specific[i]; + self->pt_specific[i] = NULL; /* see above */ + (*destructor)(val); + } } } } while (!done && iterations--); |
