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/libsasl | |
parent | d7306b64c847d897abb9ece8624fca9cf28d358f (diff) | |
download | illumos-gate-cb6207858a9fcc2feaee22e626912fba281ac969.tar.gz |
PSARC 2007/129 thr_keycreate_once
6513516 double checked locking code needs a memory barrier
Diffstat (limited to 'usr/src/lib/libsasl')
-rw-r--r-- | usr/src/lib/libsasl/lib/common.c | 20 |
1 files changed, 5 insertions, 15 deletions
diff --git a/usr/src/lib/libsasl/lib/common.c b/usr/src/lib/libsasl/lib/common.c index a4b3d896ec..baceb2ae5d 100644 --- a/usr/src/lib/libsasl/lib/common.c +++ b/usr/src/lib/libsasl/lib/common.c @@ -1,7 +1,8 @@ /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ + #pragma ident "%Z%%M% %I% %E% SMI" /* common.c - Functions that are common to server and clinet @@ -92,8 +93,7 @@ static void _sasl_dispose_context(_sasl_global_context_t *ctx); static int _sasl_getconf(void *context, const char **conf); #ifdef _INTEGRATED_SOLARIS_ -static int init_thread_set_specific = 0; -static pthread_key_t errstring_key; +static pthread_key_t errstring_key = PTHREAD_ONCE_KEY_NP; #endif /* _INTEGRATED_SOLARIS_ */ #else static const char build_ident[] = "$Build: libsasl " PACKAGE "-" VERSION " $"; @@ -1110,8 +1110,6 @@ static int sasl_usererr(int saslerr) static void free_err_tsd(void *key) { free(key); - - pthread_setspecific(errstring_key, NULL); } #endif /* _INTEGRATED_SOLARIS_ */ @@ -1216,21 +1214,13 @@ const char *sasl_errstring(int saslerr, if (s_utf8 == NULL) return s; - if (!init_thread_set_specific) { - LOCK_MUTEX(&global_mutex); - if (!init_thread_set_specific) { - if (pthread_key_create(&errstring_key, free_err_tsd) == 0) - init_thread_set_specific = 1; - } - UNLOCK_MUTEX(&global_mutex); - } - if (!init_thread_set_specific) { + if (pthread_key_create_once_np(&errstring_key, free_err_tsd) != 0) { free(s_utf8); return s; } tsd = pthread_getspecific(errstring_key); - if (tsd == NULL) + if (tsd != NULL) free(tsd); pthread_setspecific(errstring_key, s_utf8); |