diff options
author | Rich Salz <rsalz@openssl.org> | 2016-08-19 21:04:41 -0400 |
---|---|---|
committer | Rich Salz <rsalz@openssl.org> | 2016-08-19 21:04:41 -0400 |
commit | 8b8d963db5bb619fbada014f294fd09a855a2650 (patch) | |
tree | a330e959245ca6216ea42978799134be17be239f /crypto/bio | |
parent | 9e313563da23f3dc0a6db557f708726234e3f653 (diff) |
Add BIO_get_new_index()
Reviewed-by: Dr. Stephen Henson <steve@openssl.org>
Diffstat (limited to 'crypto/bio')
-rw-r--r-- | crypto/bio/b_addr.c | 4 | ||||
-rw-r--r-- | crypto/bio/bio_lcl.h | 1 | ||||
-rw-r--r-- | crypto/bio/bio_lib.c | 2 | ||||
-rw-r--r-- | crypto/bio/bio_meth.c | 12 |
4 files changed, 18 insertions, 1 deletions
diff --git a/crypto/bio/b_addr.c b/crypto/bio/b_addr.c index 4e8785fdcd..17ab3e4e83 100644 --- a/crypto/bio/b_addr.c +++ b/crypto/bio/b_addr.c @@ -19,6 +19,7 @@ #include <ctype.h> CRYPTO_RWLOCK *bio_lookup_lock; +extern CRYPTO_RWLOCK *bio_type_lock; static CRYPTO_ONCE bio_lookup_init = CRYPTO_ONCE_STATIC_INIT; /* @@ -605,7 +606,8 @@ static int addrinfo_wrap(int family, int socktype, DEFINE_RUN_ONCE_STATIC(do_bio_lookup_init) { bio_lookup_lock = CRYPTO_THREAD_lock_new(); - return (bio_lookup_lock != NULL); + bio_type_lock = CRYPTO_THREAD_lock_new(); + return bio_lookup_lock != NULL && bio_type_lock != NULL; } /*- diff --git a/crypto/bio/bio_lcl.h b/crypto/bio/bio_lcl.h index f5a886cb7c..5d0b827930 100644 --- a/crypto/bio/bio_lcl.h +++ b/crypto/bio/bio_lcl.h @@ -137,6 +137,7 @@ typedef unsigned int socklen_t; # endif extern CRYPTO_RWLOCK *bio_lookup_lock; +extern CRYPTO_RWLOCK *bio_type_lock; int BIO_ADDR_make(BIO_ADDR *ap, const struct sockaddr *sa); const struct sockaddr *BIO_ADDR_sockaddr(const BIO_ADDR *ap); diff --git a/crypto/bio/bio_lib.c b/crypto/bio/bio_lib.c index 98f3707ea5..8a00103e2c 100644 --- a/crypto/bio/bio_lib.c +++ b/crypto/bio/bio_lib.c @@ -594,5 +594,7 @@ void bio_cleanup(void) bio_sock_cleanup_int(); CRYPTO_THREAD_lock_free(bio_lookup_lock); bio_lookup_lock = NULL; + CRYPTO_THREAD_lock_free(bio_type_lock); + bio_type_lock = NULL; #endif } diff --git a/crypto/bio/bio_meth.c b/crypto/bio/bio_meth.c index d172047f55..7754b00394 100644 --- a/crypto/bio/bio_meth.c +++ b/crypto/bio/bio_meth.c @@ -9,6 +9,18 @@ #include "bio_lcl.h" +CRYPTO_RWLOCK *bio_type_lock; +static int bio_count = BIO_TYPE_START; + +int BIO_get_new_index() +{ + int newval; + + if (!CRYPTO_atomic_add(&bio_count, 1, &newval, bio_type_lock)) + return -1; + return newval; +} + BIO_METHOD *BIO_meth_new(int type, const char *name) { BIO_METHOD *biom = OPENSSL_zalloc(sizeof(BIO_METHOD)); |