Commit 2f545ae4 authored by Kurt Roeckx's avatar Kurt Roeckx
Browse files

Add support for reference counting using C11 atomics



Reviewed-by: default avatarAndy Polyakov <appro@openssl.org>
Reviewed-by: default avatarRich Salz <rsalz@openssl.org>

GH: #1500
parent b6c68982
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@

#define USE_SOCKETS
#include "e_os.h"
#include "internal/refcount.h"

/* BEGIN BIO_ADDRINFO/BIO_ADDR stuff. */

@@ -125,7 +126,7 @@ struct bio_st {
    void *ptr;
    struct bio_st *next_bio;    /* used by filter BIOs */
    struct bio_st *prev_bio;    /* used by filter BIOs */
    int references;
    CRYPTO_REF_COUNT references;
    uint64_t num_read;
    uint64_t num_write;
    CRYPTO_EX_DATA ex_data;
+2 −2
Original line number Diff line number Diff line
@@ -113,7 +113,7 @@ int BIO_free(BIO *a)
    if (a == NULL)
        return 0;

    if (CRYPTO_atomic_add(&a->references, -1, &ret, a->lock) <= 0)
    if (CRYPTO_DOWN_REF(&a->references, &ret, a->lock) <= 0)
        return 0;

    REF_PRINT_COUNT("BIO", a);
@@ -178,7 +178,7 @@ int BIO_up_ref(BIO *a)
{
    int i;

    if (CRYPTO_atomic_add(&a->references, 1, &i, a->lock) <= 0)
    if (CRYPTO_UP_REF(&a->references, &i, a->lock) <= 0)
        return 0;

    REF_PRINT_COUNT("BIO", a);
+2 −2
Original line number Diff line number Diff line
@@ -21,14 +21,14 @@ DEFINE_RUN_ONCE_STATIC(do_bio_type_init)

int BIO_get_new_index()
{
    static int bio_count = BIO_TYPE_START;
    static CRYPTO_REF_COUNT bio_count = BIO_TYPE_START;
    int newval;

    if (!RUN_ONCE(&bio_type_init, do_bio_type_init)) {
        BIOerr(BIO_F_BIO_GET_NEW_INDEX, ERR_R_MALLOC_FAILURE);
        return -1;
    }
    if (!CRYPTO_atomic_add(&bio_count, 1, &newval, bio_type_lock))
    if (!CRYPTO_UP_REF(&bio_count, &newval, bio_type_lock))
        return -1;
    return newval;
}
+2 −2
Original line number Diff line number Diff line
@@ -111,7 +111,7 @@ void DH_free(DH *r)
    if (r == NULL)
        return;

    CRYPTO_atomic_add(&r->references, -1, &i, r->lock);
    CRYPTO_DOWN_REF(&r->references, &i, r->lock);
    REF_PRINT_COUNT("DH", r);
    if (i > 0)
        return;
@@ -142,7 +142,7 @@ int DH_up_ref(DH *r)
{
    int i;

    if (CRYPTO_atomic_add(&r->references, 1, &i, r->lock) <= 0)
    if (CRYPTO_UP_REF(&r->references, &i, r->lock) <= 0)
        return 0;

    REF_PRINT_COUNT("DH", r);
+2 −1
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@
 */

#include <openssl/dh.h>
#include "internal/refcount.h"

struct dh_st {
    /*
@@ -29,7 +30,7 @@ struct dh_st {
    unsigned char *seed;
    int seedlen;
    BIGNUM *counter;
    int references;
    CRYPTO_REF_COUNT references;
    CRYPTO_EX_DATA ex_data;
    const DH_METHOD *meth;
    ENGINE *engine;
Loading