summaryrefslogtreecommitdiff
path: root/usr/src/lib/libresolv2
diff options
context:
space:
mode:
authorraf <none@none>2007-03-20 17:29:57 -0700
committerraf <none@none>2007-03-20 17:29:57 -0700
commitcb6207858a9fcc2feaee22e626912fba281ac969 (patch)
tree9e84b682e42e9c8dcd013b29690be6905e45841d /usr/src/lib/libresolv2
parentd7306b64c847d897abb9ece8624fca9cf28d358f (diff)
downloadillumos-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/libresolv2')
-rw-r--r--usr/src/lib/libresolv2/common/irs/gai_strerror.c20
-rw-r--r--usr/src/lib/libresolv2/common/irs/irs_data.c21
2 files changed, 7 insertions, 34 deletions
diff --git a/usr/src/lib/libresolv2/common/irs/gai_strerror.c b/usr/src/lib/libresolv2/common/irs/gai_strerror.c
index e9e1131729..a9e249b418 100644
--- a/usr/src/lib/libresolv2/common/irs/gai_strerror.c
+++ b/usr/src/lib/libresolv2/common/irs/gai_strerror.c
@@ -59,9 +59,7 @@ gai_strerror(int ecode) {
#ifndef DO_PTHREADS
static char buf[EAI_BUFSIZE];
#else /* DO_PTHREADS */
- static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
- static pthread_key_t key;
- static int once = 0;
+ static pthread_key_t key = PTHREAD_ONCE_KEY_NP;
char *buf;
#endif
@@ -69,20 +67,8 @@ gai_strerror(int ecode) {
return (gai_errlist[ecode]);
#ifdef DO_PTHREADS
- if (!once) {
- if (pthread_mutex_lock(&lock) != 0)
- goto unknown;
- if (!once) {
- if (pthread_key_create(&key, free) != 0) {
- pthread_mutex_unlock(&lock);
- goto unknown;
- }
- once = 1;
- }
- if (pthread_mutex_unlock(&lock) != 0)
- goto unknown;
- }
-
+ if (pthread_key_create_once_np(&key, free) != 0)
+ goto unknown;
buf = pthread_getspecific(key);
if (buf == NULL) {
buf = malloc(EAI_BUFSIZE);
diff --git a/usr/src/lib/libresolv2/common/irs/irs_data.c b/usr/src/lib/libresolv2/common/irs/irs_data.c
index 5db332a87f..874c25cef8 100644
--- a/usr/src/lib/libresolv2/common/irs/irs_data.c
+++ b/usr/src/lib/libresolv2/common/irs/irs_data.c
@@ -57,10 +57,9 @@ extern struct __res_state _res;
extern int h_errno;
#ifdef DO_PTHREADS
-static pthread_key_t key;
-static int once = 0;
+static pthread_key_t key = PTHREAD_ONCE_KEY_NP;
#else
-static struct net_data *net_data;
+static struct net_data *net_data = NULL;
#endif
void
@@ -126,22 +125,10 @@ net_data_destroy(void *p) {
struct net_data *
net_data_init(const char *conf_file) {
#ifdef DO_PTHREADS
- static pthread_mutex_t keylock = PTHREAD_MUTEX_INITIALIZER;
struct net_data *net_data;
- if (!once) {
- if (pthread_mutex_lock(&keylock) != 0)
- return (NULL);
- if (!once) {
- if (pthread_key_create(&key, net_data_destroy) != 0) {
- pthread_mutex_unlock(&keylock);
- return (NULL);
- }
- once = 1;
- }
- if (pthread_mutex_unlock(&keylock) != 0)
- return (NULL);
- }
+ if (pthread_key_create_once_np(&key, net_data_destroy) != 0)
+ return (NULL);
net_data = pthread_getspecific(key);
#endif