diff options
author | Rich Salz <rsalz@openssl.org> | 2016-08-20 19:06:43 -0400 |
---|---|---|
committer | Rich Salz <rsalz@openssl.org> | 2016-08-21 14:18:09 -0400 |
commit | 5a7ad1f08bfccbdad0f20920f9c284bba036fb70 (patch) | |
tree | 2632f6f907b85cb583a52335ca9d5e47f9a24829 /crypto/bio/bio_meth.c | |
parent | 6b1f413c3a8563a53e1b41d48d870c010541c7f5 (diff) |
Move BIO index lock creation
Reviewed-by: Richard Levitte <levitte@openssl.org>
Diffstat (limited to 'crypto/bio/bio_meth.c')
-rw-r--r-- | crypto/bio/bio_meth.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/crypto/bio/bio_meth.c b/crypto/bio/bio_meth.c index 7754b00394..c5f9f7e8e7 100644 --- a/crypto/bio/bio_meth.c +++ b/crypto/bio/bio_meth.c @@ -8,14 +8,26 @@ */ #include "bio_lcl.h" +#include <internal/thread_once.h> -CRYPTO_RWLOCK *bio_type_lock; -static int bio_count = BIO_TYPE_START; +CRYPTO_RWLOCK *bio_type_lock = NULL; +static CRYPTO_ONCE bio_type_init = CRYPTO_ONCE_STATIC_INIT; + +DEFINE_RUN_ONCE_STATIC(do_bio_type_init) +{ + bio_type_lock = CRYPTO_THREAD_lock_new(); + return bio_type_lock != NULL; +} int BIO_get_new_index() { + static int 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)) return -1; return newval; |