Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/boringssl.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Langley <agl@google.com>2015-04-13 21:04:20 +0300
committerAdam Langley <agl@google.com>2015-04-14 23:12:14 +0300
commitba3bef98d8d9f82b83e2b0729538113ee06fb2c0 (patch)
tree011917284ffcc19e799bbfa97cba7e0b7ed5cc6c /crypto/obj
parent90b5840b02ab204f2b96e958d4668a4997a94940 (diff)
obj: convert to new-style locks.
Change-Id: Idd7c37b9a0fe56f11909c2bf891bca370ef7f982 Reviewed-on: https://boringssl-review.googlesource.com/4327 Reviewed-by: Adam Langley <agl@google.com>
Diffstat (limited to 'crypto/obj')
-rw-r--r--crypto/obj/obj.c39
1 files changed, 22 insertions, 17 deletions
diff --git a/crypto/obj/obj.c b/crypto/obj/obj.c
index b04321b8..405c78db 100644
--- a/crypto/obj/obj.c
+++ b/crypto/obj/obj.c
@@ -68,21 +68,26 @@
#include <openssl/thread.h>
#include "obj_dat.h"
+#include "../internal.h"
-/* These globals are protected by CRYPTO_LOCK_OBJ. */
+
+static struct CRYPTO_STATIC_MUTEX global_added_lock = CRYPTO_STATIC_MUTEX_INIT;
+/* These globals are protected by |global_added_lock|. */
static LHASH_OF(ASN1_OBJECT) *global_added_by_data = NULL;
static LHASH_OF(ASN1_OBJECT) *global_added_by_nid = NULL;
static LHASH_OF(ASN1_OBJECT) *global_added_by_short_name = NULL;
static LHASH_OF(ASN1_OBJECT) *global_added_by_long_name = NULL;
+static struct CRYPTO_STATIC_MUTEX global_next_nid_lock =
+ CRYPTO_STATIC_MUTEX_INIT;
static unsigned global_next_nid = NUM_NID;
static int obj_next_nid(void) {
int ret;
- CRYPTO_w_lock(CRYPTO_LOCK_OBJ);
+ CRYPTO_STATIC_MUTEX_lock_write(&global_next_nid_lock);
ret = global_next_nid++;
- CRYPTO_w_unlock(CRYPTO_LOCK_OBJ);
+ CRYPTO_STATIC_MUTEX_unlock(&global_next_nid_lock);
return ret;
}
@@ -195,17 +200,17 @@ int OBJ_obj2nid(const ASN1_OBJECT *obj) {
return obj->nid;
}
- CRYPTO_r_lock(CRYPTO_LOCK_OBJ);
+ CRYPTO_STATIC_MUTEX_lock_read(&global_added_lock);
if (global_added_by_data != NULL) {
ASN1_OBJECT *match;
match = lh_ASN1_OBJECT_retrieve(global_added_by_data, obj);
if (match != NULL) {
- CRYPTO_r_unlock(CRYPTO_LOCK_OBJ);
+ CRYPTO_STATIC_MUTEX_unlock(&global_added_lock);
return match->nid;
}
}
- CRYPTO_r_unlock(CRYPTO_LOCK_OBJ);
+ CRYPTO_STATIC_MUTEX_unlock(&global_added_lock);
nid_ptr = bsearch(obj, kNIDsInOIDOrder, NUM_OBJ, sizeof(unsigned), obj_cmp);
if (nid_ptr == NULL) {
@@ -237,18 +242,18 @@ static int short_name_cmp(const void *key, const void *element) {
int OBJ_sn2nid(const char *short_name) {
const unsigned int *nid_ptr;
- CRYPTO_r_lock(CRYPTO_LOCK_OBJ);
+ CRYPTO_STATIC_MUTEX_lock_read(&global_added_lock);
if (global_added_by_short_name != NULL) {
ASN1_OBJECT *match, template;
template.sn = short_name;
match = lh_ASN1_OBJECT_retrieve(global_added_by_short_name, &template);
if (match != NULL) {
- CRYPTO_r_unlock(CRYPTO_LOCK_OBJ);
+ CRYPTO_STATIC_MUTEX_unlock(&global_added_lock);
return match->nid;
}
}
- CRYPTO_r_unlock(CRYPTO_LOCK_OBJ);
+ CRYPTO_STATIC_MUTEX_unlock(&global_added_lock);
nid_ptr = bsearch(short_name, kNIDsInShortNameOrder, NUM_SN, sizeof(unsigned), short_name_cmp);
if (nid_ptr == NULL) {
@@ -271,18 +276,18 @@ static int long_name_cmp(const void *key, const void *element) {
int OBJ_ln2nid(const char *long_name) {
const unsigned int *nid_ptr;
- CRYPTO_r_lock(CRYPTO_LOCK_OBJ);
+ CRYPTO_STATIC_MUTEX_lock_read(&global_added_lock);
if (global_added_by_long_name != NULL) {
ASN1_OBJECT *match, template;
template.ln = long_name;
match = lh_ASN1_OBJECT_retrieve(global_added_by_long_name, &template);
if (match != NULL) {
- CRYPTO_r_unlock(CRYPTO_LOCK_OBJ);
+ CRYPTO_STATIC_MUTEX_unlock(&global_added_lock);
return match->nid;
}
}
- CRYPTO_r_unlock(CRYPTO_LOCK_OBJ);
+ CRYPTO_STATIC_MUTEX_unlock(&global_added_lock);
nid_ptr = bsearch(long_name, kNIDsInLongNameOrder, NUM_LN, sizeof(unsigned), long_name_cmp);
if (nid_ptr == NULL) {
@@ -324,18 +329,18 @@ const ASN1_OBJECT *OBJ_nid2obj(int nid) {
return &kObjects[nid];
}
- CRYPTO_r_lock(CRYPTO_LOCK_OBJ);
+ CRYPTO_STATIC_MUTEX_lock_read(&global_added_lock);
if (global_added_by_nid != NULL) {
ASN1_OBJECT *match, template;
template.nid = nid;
match = lh_ASN1_OBJECT_retrieve(global_added_by_nid, &template);
if (match != NULL) {
- CRYPTO_r_unlock(CRYPTO_LOCK_OBJ);
+ CRYPTO_STATIC_MUTEX_unlock(&global_added_lock);
return match;
}
}
- CRYPTO_r_unlock(CRYPTO_LOCK_OBJ);
+ CRYPTO_STATIC_MUTEX_unlock(&global_added_lock);
err:
OPENSSL_PUT_ERROR(OBJ, OBJ_nid2obj, OBJ_R_UNKNOWN_NID);
@@ -600,7 +605,7 @@ static int obj_add_object(ASN1_OBJECT *obj) {
obj->flags &= ~(ASN1_OBJECT_FLAG_DYNAMIC | ASN1_OBJECT_FLAG_DYNAMIC_STRINGS |
ASN1_OBJECT_FLAG_DYNAMIC_DATA);
- CRYPTO_w_lock(CRYPTO_LOCK_OBJ);
+ CRYPTO_STATIC_MUTEX_lock_write(&global_added_lock);
if (global_added_by_nid == NULL) {
global_added_by_nid = lh_ASN1_OBJECT_new(hash_nid, cmp_nid);
global_added_by_data = lh_ASN1_OBJECT_new(hash_data, cmp_data);
@@ -623,7 +628,7 @@ static int obj_add_object(ASN1_OBJECT *obj) {
if (obj->ln != NULL) {
ok &= lh_ASN1_OBJECT_insert(global_added_by_long_name, &old_object, obj);
}
- CRYPTO_w_unlock(CRYPTO_LOCK_OBJ);
+ CRYPTO_STATIC_MUTEX_unlock(&global_added_lock);
return ok;
}