diff options
author | hrs <hrs@FreeBSD.org> | 2011-05-29 02:53:52 +0000 |
---|---|---|
committer | hrs <hrs@FreeBSD.org> | 2011-05-29 02:53:52 +0000 |
commit | 8fe640108653f13042f1b15213769e338aa524f6 (patch) | |
tree | 91f5675a7c792e61d68635707501027daa3f566f /lib/libc/rpc/mt_misc.c | |
parent | 97f64b711efa9ff0011bef5d46cf9645638a38f9 (diff) | |
parent | f3726238c8e8206eb1df4cfaf3f00947ceba3cce (diff) | |
download | FreeBSD-src-8fe640108653f13042f1b15213769e338aa524f6.zip FreeBSD-src-8fe640108653f13042f1b15213769e338aa524f6.tar.gz |
Merge from head@222434.
Diffstat (limited to 'lib/libc/rpc/mt_misc.c')
-rw-r--r-- | lib/libc/rpc/mt_misc.c | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/lib/libc/rpc/mt_misc.c b/lib/libc/rpc/mt_misc.c index 6241611..7abcaed 100644 --- a/lib/libc/rpc/mt_misc.c +++ b/lib/libc/rpc/mt_misc.c @@ -28,7 +28,6 @@ __FBSDID("$FreeBSD$"); #define proglst_lock __proglst_lock #define rpcsoc_lock __rpcsoc_lock #define svcraw_lock __svcraw_lock -#define tsd_lock __tsd_lock #define xprtlist_lock __xprtlist_lock /* protects the services list (svc.c) */ @@ -76,33 +75,33 @@ pthread_mutex_t rpcsoc_lock = PTHREAD_MUTEX_INITIALIZER; /* svc_raw.c serialization */ pthread_mutex_t svcraw_lock = PTHREAD_MUTEX_INITIALIZER; -/* protects TSD key creation */ -pthread_mutex_t tsd_lock = PTHREAD_MUTEX_INITIALIZER; - /* xprtlist (svc_generic.c) */ pthread_mutex_t xprtlist_lock = PTHREAD_MUTEX_INITIALIZER; #undef rpc_createerr struct rpc_createerr rpc_createerr; +static thread_key_t rce_key; +static once_t rce_once = ONCE_INITIALIZER; +static int rce_key_error; + +static void +rce_key_init(void) +{ + + rce_key_error = thr_keycreate(&rce_key, free); +} struct rpc_createerr * __rpc_createerr() { - static thread_key_t rce_key = 0; struct rpc_createerr *rce_addr = 0; if (thr_main()) return (&rpc_createerr); - if ((rce_addr = - (struct rpc_createerr *)thr_getspecific(rce_key)) != 0) { - mutex_lock(&tsd_lock); - if (thr_keycreate(&rce_key, free) != 0) { - mutex_unlock(&tsd_lock); - return (&rpc_createerr); - } - mutex_unlock(&tsd_lock); - } + if (thr_once(&rce_once, rce_key_init) != 0 || rce_key_error != 0) + return (&rpc_createerr); + rce_addr = (struct rpc_createerr *)thr_getspecific(rce_key); if (!rce_addr) { rce_addr = (struct rpc_createerr *) malloc(sizeof (struct rpc_createerr)); |