summaryrefslogtreecommitdiffstats
path: root/lib/libc/rpc/rpc_generic.c
diff options
context:
space:
mode:
authorhrs <hrs@FreeBSD.org>2011-05-29 02:53:52 +0000
committerhrs <hrs@FreeBSD.org>2011-05-29 02:53:52 +0000
commit8fe640108653f13042f1b15213769e338aa524f6 (patch)
tree91f5675a7c792e61d68635707501027daa3f566f /lib/libc/rpc/rpc_generic.c
parent97f64b711efa9ff0011bef5d46cf9645638a38f9 (diff)
parentf3726238c8e8206eb1df4cfaf3f00947ceba3cce (diff)
downloadFreeBSD-src-8fe640108653f13042f1b15213769e338aa524f6.zip
FreeBSD-src-8fe640108653f13042f1b15213769e338aa524f6.tar.gz
Merge from head@222434.
Diffstat (limited to 'lib/libc/rpc/rpc_generic.c')
-rw-r--r--lib/libc/rpc/rpc_generic.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/lib/libc/rpc/rpc_generic.c b/lib/libc/rpc/rpc_generic.c
index 81bd92b..ab259d5 100644
--- a/lib/libc/rpc/rpc_generic.c
+++ b/lib/libc/rpc/rpc_generic.c
@@ -221,6 +221,18 @@ getnettype(nettype)
return (_rpctypelist[i].type);
}
+static thread_key_t tcp_key, udp_key;
+static once_t keys_once = ONCE_INITIALIZER;
+static int tcp_key_error, udp_key_error;
+
+static void
+keys_init(void)
+{
+
+ tcp_key_error = thr_keycreate(&tcp_key, free);
+ udp_key_error = thr_keycreate(&udp_key, free);
+}
+
/*
* For the given nettype (tcp or udp only), return the first structure found.
* This should be freed by calling freenetconfigent()
@@ -236,25 +248,15 @@ __rpc_getconfip(nettype)
static char *netid_udp_main;
struct netconfig *dummy;
int main_thread;
- static thread_key_t tcp_key, udp_key;
if ((main_thread = thr_main())) {
netid_udp = netid_udp_main;
netid_tcp = netid_tcp_main;
} else {
- if (tcp_key == 0) {
- mutex_lock(&tsd_lock);
- if (tcp_key == 0)
- thr_keycreate(&tcp_key, free);
- mutex_unlock(&tsd_lock);
- }
+ if (thr_once(&keys_once, keys_init) != 0 ||
+ tcp_key_error != 0 || udp_key_error != 0)
+ return (NULL);
netid_tcp = (char *)thr_getspecific(tcp_key);
- if (udp_key == 0) {
- mutex_lock(&tsd_lock);
- if (udp_key == 0)
- thr_keycreate(&udp_key, free);
- mutex_unlock(&tsd_lock);
- }
netid_udp = (char *)thr_getspecific(udp_key);
}
if (!netid_udp && !netid_tcp) {
OpenPOWER on IntegriCloud