diff options
author | Alessandro Ghedini <alessandro@ghedini.me> | 2016-02-26 12:21:15 +0000 |
---|---|---|
committer | Rich Salz <rsalz@openssl.org> | 2016-03-08 11:10:34 -0500 |
commit | 03273d61e742b02485831ce739e4a6c9b197e3f3 (patch) | |
tree | 409404f29d10943739c95a0e2333d6431168434b /crypto/evp | |
parent | fb46be034816e5fe9f04fd39da960d34dbf2f52d (diff) | |
download | openssl-03273d61e742b02485831ce739e4a6c9b197e3f3.tar.gz |
Convert CRYPTO_LOCK_EVP_PKEY to new multi-threading API
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
Diffstat (limited to 'crypto/evp')
-rw-r--r-- | crypto/evp/p_lib.c | 16 | ||||
-rw-r--r-- | crypto/evp/pmeth_fn.c | 2 | ||||
-rw-r--r-- | crypto/evp/pmeth_lib.c | 6 |
3 files changed, 16 insertions, 8 deletions
diff --git a/crypto/evp/p_lib.c b/crypto/evp/p_lib.c index b34a268c89..a7d624427e 100644 --- a/crypto/evp/p_lib.c +++ b/crypto/evp/p_lib.c @@ -190,18 +190,25 @@ EVP_PKEY *EVP_PKEY_new(void) if (ret == NULL) { EVPerr(EVP_F_EVP_PKEY_NEW, ERR_R_MALLOC_FAILURE); - return (NULL); + return NULL; } ret->type = EVP_PKEY_NONE; ret->save_type = EVP_PKEY_NONE; ret->references = 1; ret->save_parameters = 1; - return (ret); + ret->lock = CRYPTO_THREAD_lock_new(); + if (ret->lock == NULL) { + EVPerr(EVP_F_EVP_PKEY_NEW, ERR_R_MALLOC_FAILURE); + OPENSSL_free(ret); + return NULL; + } + return ret; } void EVP_PKEY_up_ref(EVP_PKEY *pkey) { - CRYPTO_add(&pkey->references, 1, CRYPTO_LOCK_EVP_PKEY); + int i; + CRYPTO_atomic_add(&pkey->references, 1, &i, pkey->lock); } /* @@ -416,7 +423,7 @@ void EVP_PKEY_free(EVP_PKEY *x) if (x == NULL) return; - i = CRYPTO_add(&x->references, -1, CRYPTO_LOCK_EVP_PKEY); + CRYPTO_atomic_add(&x->references, -1, &i, x->lock); REF_PRINT_COUNT("EVP_PKEY", x); if (i > 0) return; @@ -437,6 +444,7 @@ static void EVP_PKEY_free_it(EVP_PKEY *x) ENGINE_finish(x->engine); x->engine = NULL; #endif + CRYPTO_THREAD_lock_free(x->lock); } static int unsup_alg(BIO *out, const EVP_PKEY *pkey, int indent, diff --git a/crypto/evp/pmeth_fn.c b/crypto/evp/pmeth_fn.c index 11c319dd41..872947a6aa 100644 --- a/crypto/evp/pmeth_fn.c +++ b/crypto/evp/pmeth_fn.c @@ -324,7 +324,7 @@ int EVP_PKEY_derive_set_peer(EVP_PKEY_CTX *ctx, EVP_PKEY *peer) return ret; } - CRYPTO_add(&peer->references, 1, CRYPTO_LOCK_EVP_PKEY); + EVP_PKEY_up_ref(peer); return 1; } diff --git a/crypto/evp/pmeth_lib.c b/crypto/evp/pmeth_lib.c index 9ae61cf22e..26bec9a64b 100644 --- a/crypto/evp/pmeth_lib.c +++ b/crypto/evp/pmeth_lib.c @@ -175,7 +175,7 @@ static EVP_PKEY_CTX *int_ctx_new(EVP_PKEY *pkey, ENGINE *e, int id) ret->operation = EVP_PKEY_OP_UNDEFINED; ret->pkey = pkey; if (pkey) - CRYPTO_add(&pkey->references, 1, CRYPTO_LOCK_EVP_PKEY); + EVP_PKEY_up_ref(pkey); if (pmeth->init) { if (pmeth->init(ret) <= 0) { @@ -288,12 +288,12 @@ EVP_PKEY_CTX *EVP_PKEY_CTX_dup(EVP_PKEY_CTX *pctx) #endif if (pctx->pkey) - CRYPTO_add(&pctx->pkey->references, 1, CRYPTO_LOCK_EVP_PKEY); + EVP_PKEY_up_ref(pctx->pkey); rctx->pkey = pctx->pkey; if (pctx->peerkey) - CRYPTO_add(&pctx->peerkey->references, 1, CRYPTO_LOCK_EVP_PKEY); + EVP_PKEY_up_ref(pctx->peerkey); rctx->peerkey = pctx->peerkey; |