diff options
author | Matt Caswell <matt@openssl.org> | 2020-12-22 16:16:51 +0100 |
---|---|---|
committer | Dmitry Belyavskiy <beldmit@gmail.com> | 2020-12-24 12:36:40 +0100 |
commit | ae031148fde2b55238d56dcbe4ac05625382d970 (patch) | |
tree | ea60b6234e12a1f402973c4f20c91ff9780ee930 /crypto/init.c | |
parent | Cache Digest constants (diff) | |
download | openssl-ae031148fde2b55238d56dcbe4ac05625382d970.tar.xz openssl-ae031148fde2b55238d56dcbe4ac05625382d970.zip |
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 <beldmit@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/13731)
Diffstat (limited to 'crypto/init.c')
-rw-r--r-- | crypto/init.c | 25 |
1 files 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 @@ -234,7 +234,15 @@ 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; } |