summaryrefslogtreecommitdiffstats
path: root/crypto/engine/eng_lib.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/engine/eng_lib.c')
-rw-r--r--crypto/engine/eng_lib.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/crypto/engine/eng_lib.c b/crypto/engine/eng_lib.c
index 15c2c6ff68..dd4734202e 100644
--- a/crypto/engine/eng_lib.c
+++ b/crypto/engine/eng_lib.c
@@ -59,12 +59,23 @@
#include "eng_int.h"
#include <openssl/rand.h>
+CRYPTO_RWLOCK *global_engine_lock;
+
+CRYPTO_ONCE engine_lock_init = CRYPTO_ONCE_STATIC_INIT;
+
/* The "new"/"free" stuff first */
+void do_engine_lock_init(void)
+{
+ global_engine_lock = CRYPTO_THREAD_lock_new();
+}
+
ENGINE *ENGINE_new(void)
{
ENGINE *ret;
+ CRYPTO_THREAD_run_once(&engine_lock_init, do_engine_lock_init);
+
ret = OPENSSL_zalloc(sizeof(*ret));
if (ret == NULL) {
ENGINEerr(ENGINE_F_ENGINE_NEW, ERR_R_MALLOC_FAILURE);
@@ -108,7 +119,7 @@ int engine_free_util(ENGINE *e, int locked)
if (e == NULL)
return 1;
if (locked)
- i = CRYPTO_add(&e->struct_ref, -1, CRYPTO_LOCK_ENGINE);
+ CRYPTO_atomic_add(&e->struct_ref, -1, &i, global_engine_lock);
else
i = --e->struct_ref;
engine_ref_debug(e, 0, -1)
@@ -201,6 +212,7 @@ void ENGINE_cleanup(void)
* registering a cleanup callback.
*/
RAND_set_rand_method(NULL);
+ CRYPTO_THREAD_lock_free(global_engine_lock);
}
/* Now the "ex_data" support */