From dc651e62dfb3627eb95f982adfae545d2c828a26 Mon Sep 17 00:00:00 2001 From: nathanw Date: Tue, 21 Jan 2003 23:29:22 +0000 Subject: 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. --- lib/libpthread/pthread_specific.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'lib/libpthread/pthread_specific.c') 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--); -- cgit