diff options
| author | raf <none@none> | 2007-03-20 17:29:57 -0700 |
|---|---|---|
| committer | raf <none@none> | 2007-03-20 17:29:57 -0700 |
| commit | cb6207858a9fcc2feaee22e626912fba281ac969 (patch) | |
| tree | 9e84b682e42e9c8dcd013b29690be6905e45841d /usr/src/lib/libpool | |
| parent | d7306b64c847d897abb9ece8624fca9cf28d358f (diff) | |
| download | illumos-joyent-cb6207858a9fcc2feaee22e626912fba281ac969.tar.gz | |
PSARC 2007/129 thr_keycreate_once
6513516 double checked locking code needs a memory barrier
Diffstat (limited to 'usr/src/lib/libpool')
| -rw-r--r-- | usr/src/lib/libpool/common/pool.c | 23 |
1 files changed, 6 insertions, 17 deletions
diff --git a/usr/src/lib/libpool/common/pool.c b/usr/src/lib/libpool/common/pool.c index 31e725e439..bcd8c9af28 100644 --- a/usr/src/lib/libpool/common/pool.c +++ b/usr/src/lib/libpool/common/pool.c @@ -20,7 +20,7 @@ */ /* - * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -31,6 +31,7 @@ #include <stdlib.h> #include <string.h> #include <thread.h> +#include <pthread.h> #include <synch.h> #include <unistd.h> #include <stropts.h> @@ -112,9 +113,7 @@ const char pool_info_location[] = "/dev/pool"; */ static const char static_location[] = "/etc/pooladm.conf"; static const char dynamic_location[] = "/dev/poolctl"; -static mutex_t keylock; -static thread_key_t errkey; -static int keyonce = 0; +static thread_key_t errkey = THR_ONCE_KEY; /* * libpool error code @@ -611,14 +610,7 @@ pool_seterror(int errval) pool_errval = errval; return; } - if (keyonce == 0) { - (void) mutex_lock(&keylock); - if (keyonce == 0) { - (void) thr_keycreate(&errkey, 0); - keyonce++; - } - (void) mutex_unlock(&keylock); - } + (void) thr_keycreate_once(&errkey, 0); (void) thr_setspecific(errkey, (void *)(intptr_t)errval); } @@ -629,14 +621,11 @@ pool_seterror(int errval) int pool_error(void) { - void *errval; - if (thr_main()) return (pool_errval); - if (keyonce == 0) + if (errkey == THR_ONCE_KEY) return (POE_OK); - (void) thr_getspecific(errkey, &errval); - return ((intptr_t)errval); + return ((uintptr_t)pthread_getspecific(errkey)); } /* |
