#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);
e->dsa_meth = NULL;
e->dh_meth = NULL;
e->rand_meth = NULL;
- e->store_meth = NULL;
e->ciphers = NULL;
e->digests = NULL;
e->destroy = NULL;
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)
if (i > 0)
return 1;
-#ifdef REF_CHECK
- if (i < 0) {
- fprintf(stderr, "ENGINE_free, bad structural reference count\n");
- abort();
- }
-#endif
+ REF_ASSERT_ISNT(i < 0);
/* Free up any dynamically allocated public key methods */
engine_pkey_meths_free(e);
engine_pkey_asn1_meths_free(e);
* registering a cleanup callback.
*/
RAND_set_rand_method(NULL);
+ CRYPTO_THREAD_lock_free(global_engine_lock);
}
/* Now the "ex_data" support */