summaryrefslogtreecommitdiffstats
path: root/crypto/core_fetch.c
diff options
context:
space:
mode:
authorRichard Levitte <levitte@openssl.org>2021-06-14 09:25:53 +0200
committerRichard Levitte <levitte@openssl.org>2021-06-15 15:06:04 +0200
commit9067cf6ccdce0a73922f06937e54c2fce2752038 (patch)
tree88e4aff0bd89144982e4fa231558a20c40dad388 /crypto/core_fetch.c
parent515480be79de6907fcf0f7797aa0d3cd45e7d33c (diff)
CORE: Move away the allocation of the temporary no_cache method store
The responsibility for managing the temporary store for methods from algorithm implementations flaged "no_store" is moved up to the diverse method fetching functions. This allows them to allocate it "just in time", or in other words not at all if there is not such algorithm implementation. This makes this temporary store more flexible if it's needed outside of the core fetching functionality, and slightly faster when this temporary store isn't necessary at all. Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: Paul Dale <pauli@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/15737)
Diffstat (limited to 'crypto/core_fetch.c')
-rw-r--r--crypto/core_fetch.c46
1 files changed, 20 insertions, 26 deletions
diff --git a/crypto/core_fetch.c b/crypto/core_fetch.c
index 0c30f985d6..fade75f4c9 100644
--- a/crypto/core_fetch.c
+++ b/crypto/core_fetch.c
@@ -83,19 +83,25 @@ static void ossl_method_construct_this(OSSL_PROVIDER *provider,
*/
if (data->force_store || !no_store) {
+ /* If we haven't been told not to store, add to the global store */
+ data->mcm->put(data->libctx, NULL, method, provider,
+ data->operation_id, algo->algorithm_names,
+ algo->property_definition, data->mcm_data);
+ } else {
/*
- * If we haven't been told not to store,
- * add to the global store
+ * If we have been told not to store the method "permanently", we
+ * ask for a temporary store, and store the method there.
+ * The owner of |data->mcm| is completely responsible for managing
+ * that temporary store.
*/
- data->mcm->put(data->libctx, NULL, method, provider,
+ if ((data->store = data->mcm->get_tmp_store(data->mcm_data)) == NULL)
+ return;
+
+ data->mcm->put(data->libctx, data->store, method, provider,
data->operation_id, algo->algorithm_names,
algo->property_definition, data->mcm_data);
}
- data->mcm->put(data->libctx, data->store, method, provider,
- data->operation_id, algo->algorithm_names,
- algo->property_definition, data->mcm_data);
-
/* refcnt-- because we're dropping the reference */
data->mcm->destruct(method, data->mcm_data);
}
@@ -109,14 +115,8 @@ void *ossl_method_construct(OSSL_LIB_CTX *libctx, int operation_id,
if ((method = mcm->get(libctx, NULL, mcm_data)) == NULL) {
struct construct_data_st cbdata;
- /*
- * We have a temporary store to be able to easily search among new
- * items, or items that should find themselves in the global store.
- */
- if ((cbdata.store = mcm->alloc_tmp_store(libctx)) == NULL)
- goto fin;
-
cbdata.libctx = libctx;
+ cbdata.store = NULL;
cbdata.operation_id = operation_id;
cbdata.force_store = force_store;
cbdata.mcm = mcm;
@@ -127,20 +127,14 @@ void *ossl_method_construct(OSSL_LIB_CTX *libctx, int operation_id,
ossl_method_construct_postcondition,
&cbdata);
- method = mcm->get(libctx, cbdata.store, mcm_data);
- if (method == NULL) {
- /*
- * If we get here then we did not construct the method that we
- * attempted to construct. It's possible that another thread got
- * there first and so we skipped construction (pre-condition
- * failed). We check the global store again to see if it has
- * appeared by now.
- */
+ /* If there is a temporary store, try there first */
+ if (cbdata.store != NULL)
+ method = mcm->get(libctx, cbdata.store, mcm_data);
+
+ /* If no method was found yet, try the global store */
+ if (method == NULL)
method = mcm->get(libctx, NULL, mcm_data);
- }
- mcm->dealloc_tmp_store(cbdata.store);
}
- fin:
return method;
}