summaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authorMatt Caswell <matt@openssl.org>2020-12-22 15:16:51 +0000
committerDmitry Belyavskiy <beldmit@gmail.com>2020-12-24 12:36:40 +0100
commitae031148fde2b55238d56dcbe4ac05625382d970 (patch)
treeea60b6234e12a1f402973c4f20c91ff9780ee930 /crypto
parent38f7931429859a3bd07725dbc451c0b4cac26a10 (diff)
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')
-rw-r--r--crypto/init.c25
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;
}