From f989cd8c0bb3c579d112294bf8e304647b334ee8 Mon Sep 17 00:00:00 2001 From: Alessandro Ghedini Date: Fri, 4 Mar 2016 15:24:26 +0000 Subject: [PATCH] Convert CRYPTO_LOCK_GET*BYNAME to new multi-threading API Reviewed-by: Matt Caswell Reviewed-by: Rich Salz --- crypto/bio/b_addr.c | 17 +++++++++++++---- include/openssl/crypto.h | 2 -- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/crypto/bio/b_addr.c b/crypto/bio/b_addr.c index 6125e86124..0a6c5e9713 100644 --- a/crypto/bio/b_addr.c +++ b/crypto/bio/b_addr.c @@ -55,12 +55,16 @@ #include #include "bio_lcl.h" +#include "internal/threads.h" #ifndef OPENSSL_NO_SOCK #include #include #include +static CRYPTO_RWLOCK *bio_lookup_lock; +static CRYPTO_ONCE bio_lookup_init = CRYPTO_ONCE_STATIC_INIT; + /* * Throughout this file and bio_lcl.h, the existence of the macro * AI_PASSIVE is used to detect the availability of struct addrinfo, @@ -623,6 +627,11 @@ static int addrinfo_wrap(int family, int socktype, return 1; } +static void do_bio_lookup_init(void) +{ + bio_lookup_lock = CRYPTO_THREAD_lock_new(); +} + /*- * BIO_lookup - look up the node and service you want to connect to. * @node: the node you want to connect to. @@ -735,8 +744,9 @@ int BIO_lookup(const char *host, const char *service, #endif char *proto = NULL; - CRYPTO_w_lock(CRYPTO_LOCK_GETHOSTBYNAME); - CRYPTO_w_lock(CRYPTO_LOCK_GETSERVBYNAME); + CRYPTO_THREAD_run_once(&bio_lookup_init, do_bio_lookup_init); + + CRYPTO_THREAD_write_lock(bio_lookup_lock); he_fallback_address = INADDR_ANY; if (host == NULL) { he = &he_fallback; @@ -838,8 +848,7 @@ int BIO_lookup(const char *host, const char *service, ret = 1; } err: - CRYPTO_w_unlock(CRYPTO_LOCK_GETSERVBYNAME); - CRYPTO_w_unlock(CRYPTO_LOCK_GETHOSTBYNAME); + CRYPTO_THREAD_unlock(bio_lookup_lock); } return ret; diff --git a/include/openssl/crypto.h b/include/openssl/crypto.h index bcc5aee94c..b3c669d57e 100644 --- a/include/openssl/crypto.h +++ b/include/openssl/crypto.h @@ -186,8 +186,6 @@ extern "C" { # define CRYPTO_LOCK_RAND2 19 # define CRYPTO_LOCK_MALLOC 20 # define CRYPTO_LOCK_BIO 21 -# define CRYPTO_LOCK_GETHOSTBYNAME 22 -# define CRYPTO_LOCK_GETSERVBYNAME 23 # define CRYPTO_LOCK_READDIR 24 # define CRYPTO_LOCK_RSA_BLINDING 25 # define CRYPTO_LOCK_DH 26 -- 2.25.1