The branch master has been updated via ae031148fde2b55238d56dcbe4ac05625382d970 (commit) from 38f7931429859a3bd07725dbc451c0b4cac26a10 (commit)
- Log ----------------------------------------------------------------- commit ae031148fde2b55238d56dcbe4ac05625382d970 Author: Matt Caswell <m...@openssl.org> Date: Tue Dec 22 15:16:51 2020 +0000 Optimise OPENSSL_init_crypto to not need a lock when loading config Most of the time we don't have any explicit settings when loading a config file. Therefore we optimise things so that we don't need to use a lock in that instance. Partially addresses performance issues in #13725 Reviewed-by: Dmitry Belyavskiy <beld...@gmail.com> (Merged from https://github.com/openssl/openssl/pull/13731) ----------------------------------------------------------------------- Summary of changes: crypto/init.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/crypto/init.c b/crypto/init.c index ba8706655b..f1100df169 100644 --- a/crypto/init.c +++ b/crypto/init.c @@ -233,8 +233,16 @@ static CRYPTO_ONCE config = CRYPTO_ONCE_STATIC_INIT; static int config_inited = 0; static const OPENSSL_INIT_SETTINGS *conf_settings = NULL; DEFINE_RUN_ONCE_STATIC(ossl_init_config) +{ + int ret = openssl_config_int(NULL); + + config_inited = 1; + return ret; +} +DEFINE_RUN_ONCE_STATIC_ALT(ossl_init_config_settings, ossl_init_config) { int ret = openssl_config_int(conf_settings); + config_inited = 1; return ret; } @@ -539,11 +547,18 @@ int OPENSSL_init_crypto(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings) if (opts & OPENSSL_INIT_LOAD_CONFIG) { int ret; - CRYPTO_THREAD_write_lock(init_lock); - conf_settings = settings; - ret = RUN_ONCE(&config, ossl_init_config); - conf_settings = NULL; - CRYPTO_THREAD_unlock(init_lock); + + if (settings == NULL) { + ret = RUN_ONCE(&config, ossl_init_config); + } else { + CRYPTO_THREAD_write_lock(init_lock); + conf_settings = settings; + ret = RUN_ONCE_ALT(&config, ossl_init_config_settings, + ossl_init_config); + conf_settings = NULL; + CRYPTO_THREAD_unlock(init_lock); + } + if (ret <= 0) return 0; }