encoder: update to structure based atomics

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/21260)
This commit is contained in:
Pauli 2023-06-22 09:41:30 +10:00
parent 4eecc6aa5d
commit 7d6ab12106
3 changed files with 8 additions and 15 deletions

View File

@ -31,14 +31,11 @@ static OSSL_DECODER *ossl_decoder_new(void)
if ((decoder = OPENSSL_zalloc(sizeof(*decoder))) == NULL)
return NULL;
if ((decoder->base.lock = CRYPTO_THREAD_lock_new()) == NULL) {
if (!CRYPTO_NEW_REF(&decoder->base.refcnt, 1)) {
OSSL_DECODER_free(decoder);
ERR_raise(ERR_LIB_OSSL_DECODER, ERR_R_CRYPTO_LIB);
return NULL;
}
decoder->base.refcnt = 1;
return decoder;
}
@ -46,7 +43,7 @@ int OSSL_DECODER_up_ref(OSSL_DECODER *decoder)
{
int ref = 0;
CRYPTO_UP_REF(&decoder->base.refcnt, &ref, decoder->base.lock);
CRYPTO_UP_REF(&decoder->base.refcnt, &ref);
return 1;
}
@ -57,13 +54,13 @@ void OSSL_DECODER_free(OSSL_DECODER *decoder)
if (decoder == NULL)
return;
CRYPTO_DOWN_REF(&decoder->base.refcnt, &ref, decoder->base.lock);
CRYPTO_DOWN_REF(&decoder->base.refcnt, &ref);
if (ref > 0)
return;
OPENSSL_free(decoder->base.name);
ossl_property_free(decoder->base.parsed_propdef);
ossl_provider_free(decoder->base.prov);
CRYPTO_THREAD_lock_free(decoder->base.lock);
CRYPTO_FREE_REF(&decoder->base.refcnt);
OPENSSL_free(decoder);
}

View File

@ -25,7 +25,6 @@ struct ossl_endecode_base_st {
OSSL_PROPERTY_LIST *parsed_propdef;
CRYPTO_REF_COUNT refcnt;
CRYPTO_RWLOCK *lock;
};
struct ossl_encoder_st {

View File

@ -31,14 +31,11 @@ static OSSL_ENCODER *ossl_encoder_new(void)
if ((encoder = OPENSSL_zalloc(sizeof(*encoder))) == NULL)
return NULL;
if ((encoder->base.lock = CRYPTO_THREAD_lock_new()) == NULL) {
if (!CRYPTO_NEW_REF(&encoder->base.refcnt, 1)) {
OSSL_ENCODER_free(encoder);
ERR_raise(ERR_LIB_OSSL_ENCODER, ERR_R_CRYPTO_LIB);
return NULL;
}
encoder->base.refcnt = 1;
return encoder;
}
@ -46,7 +43,7 @@ int OSSL_ENCODER_up_ref(OSSL_ENCODER *encoder)
{
int ref = 0;
CRYPTO_UP_REF(&encoder->base.refcnt, &ref, encoder->base.lock);
CRYPTO_UP_REF(&encoder->base.refcnt, &ref);
return 1;
}
@ -57,13 +54,13 @@ void OSSL_ENCODER_free(OSSL_ENCODER *encoder)
if (encoder == NULL)
return;
CRYPTO_DOWN_REF(&encoder->base.refcnt, &ref, encoder->base.lock);
CRYPTO_DOWN_REF(&encoder->base.refcnt, &ref);
if (ref > 0)
return;
OPENSSL_free(encoder->base.name);
ossl_property_free(encoder->base.parsed_propdef);
ossl_provider_free(encoder->base.prov);
CRYPTO_THREAD_lock_free(encoder->base.lock);
CRYPTO_FREE_REF(&encoder->base.refcnt);
OPENSSL_free(encoder);
}