* OK, we return a functional reference which is also a structural
* reference.
*/
- if (!CRYPTO_UP_REF(&e->struct_ref, &ref, e->refcnt_lock)) {
+ if (!CRYPTO_UP_REF(&e->struct_ref, &ref)) {
e->finish(e);
return 0;
}
}
if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL)
return NULL;
- ret->struct_ref = 1;
- ENGINE_REF_PRINT(ret, 0, 1);
- ret->refcnt_lock = CRYPTO_THREAD_lock_new();
- if (ret->refcnt_lock == NULL) {
+ if (!CRYPTO_NEW_REF(&ret->struct_ref, 1)) {
OPENSSL_free(ret);
return NULL;
}
+ ENGINE_REF_PRINT(ret, 0, 1);
if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_ENGINE, ret, &ret->ex_data)) {
- CRYPTO_THREAD_lock_free(ret->refcnt_lock);
+ CRYPTO_FREE_REF(&ret->struct_ref);
OPENSSL_free(ret);
return NULL;
}
if (e == NULL)
return 1;
- CRYPTO_DOWN_REF(&e->struct_ref, &i, e->refcnt_lock);
+ CRYPTO_DOWN_REF(&e->struct_ref, &i);
ENGINE_REF_PRINT(e, 0, -1);
if (i > 0)
return 1;
e->destroy(e);
engine_remove_dynamic_id(e, not_locked);
CRYPTO_free_ex_data(CRYPTO_EX_INDEX_ENGINE, e, &e->ex_data);
- CRYPTO_THREAD_lock_free(e->refcnt_lock);
+ CRYPTO_FREE_REF(&e->struct_ref);
OPENSSL_free(e);
return 1;
}
/*
* Having the engine in the list assumes a structural reference.
*/
- if (!CRYPTO_UP_REF(&e->struct_ref, &ref, e->refcnt_lock)) {
+ if (!CRYPTO_UP_REF(&e->struct_ref, &ref)) {
ERR_raise(ERR_LIB_ENGINE, ENGINE_R_INTERNAL_LIST_ERROR);
return 0;
}
if (engine_list_head == NULL) {
/* We are adding to an empty list. */
if (engine_list_tail != NULL) {
- CRYPTO_DOWN_REF(&e->struct_ref, &ref, e->refcnt_lock);
+ CRYPTO_DOWN_REF(&e->struct_ref, &ref);
ERR_raise(ERR_LIB_ENGINE, ENGINE_R_INTERNAL_LIST_ERROR);
return 0;
}
} else {
/* We are adding to the tail of an existing list. */
if ((engine_list_tail == NULL) || (engine_list_tail->next != NULL)) {
- CRYPTO_DOWN_REF(&e->struct_ref, &ref, e->refcnt_lock);
+ CRYPTO_DOWN_REF(&e->struct_ref, &ref);
ERR_raise(ERR_LIB_ENGINE, ENGINE_R_INTERNAL_LIST_ERROR);
return 0;
}
if (ret) {
int ref;
- if (!CRYPTO_UP_REF(&ret->struct_ref, &ref, ret->refcnt_lock)) {
+ if (!CRYPTO_UP_REF(&ret->struct_ref, &ref)) {
ERR_raise(ERR_LIB_ENGINE, ERR_R_CRYPTO_LIB);
return NULL;
}
if (ret) {
int ref;
- if (!CRYPTO_UP_REF(&ret->struct_ref, &ref, ret->refcnt_lock)) {
+ if (!CRYPTO_UP_REF(&ret->struct_ref, &ref)) {
ERR_raise(ERR_LIB_ENGINE, ERR_R_CRYPTO_LIB);
return NULL;
}
int ref;
/* Return a valid structural reference to the next ENGINE */
- if (!CRYPTO_UP_REF(&ret->struct_ref, &ref, ret->refcnt_lock)) {
+ if (!CRYPTO_UP_REF(&ret->struct_ref, &ref)) {
ERR_raise(ERR_LIB_ENGINE, ERR_R_CRYPTO_LIB);
return NULL;
}
int ref;
/* Return a valid structural reference to the next ENGINE */
- if (!CRYPTO_UP_REF(&ret->struct_ref, &ref, ret->refcnt_lock)) {
+ if (!CRYPTO_UP_REF(&ret->struct_ref, &ref)) {
ERR_raise(ERR_LIB_ENGINE, ERR_R_CRYPTO_LIB);
return NULL;
}
} else {
int ref;
- if (!CRYPTO_UP_REF(&iterator->struct_ref, &ref,
- iterator->refcnt_lock)) {
+ if (!CRYPTO_UP_REF(&iterator->struct_ref, &ref)) {
CRYPTO_THREAD_unlock(global_engine_lock);
ERR_raise(ERR_LIB_ENGINE, ERR_R_CRYPTO_LIB);
return NULL;
ERR_raise(ERR_LIB_ENGINE, ERR_R_PASSED_NULL_PARAMETER);
return 0;
}
- CRYPTO_UP_REF(&e->struct_ref, &i, global_engine_lock);
+ CRYPTO_UP_REF(&e->struct_ref, &i);
return 1;
}
* This prints the engine's pointer address, "struct" or "funct" to
* indicate the reference type, the before and after reference count, and
* the file:line-number pair. The "ENGINE_REF_PRINT" statements must come
- * *after* the change. Since this is for tracing only we do not concern
- * ourselves with using atomic primitives for reading the struct_ref
+ * *after* the change.
*/
# define ENGINE_REF_PRINT(e, isfunct, diff) \
OSSL_TRACE6(ENGINE_REF_COUNT, \
(void *)(e), (isfunct ? "funct" : "struct"), \
((isfunct) \
? ((e)->funct_ref - (diff)) \
- : ((e)->struct_ref - (diff))), \
- ((isfunct) ? (e)->funct_ref : (e)->struct_ref), \
+ : (eng_struct_ref(e) - (diff))), \
+ ((isfunct) ? (e)->funct_ref : eng_struct_ref(e)), \
(OPENSSL_FILE), (OPENSSL_LINE))
/*
int flags;
/* reference count on the structure itself */
CRYPTO_REF_COUNT struct_ref;
- CRYPTO_RWLOCK *refcnt_lock;
/*
* reference count on usability of the engine type. NB: This controls the
* loading and initialisation of any functionality required by this
DEFINE_LHASH_OF_EX(ENGINE_PILE);
+static ossl_unused ossl_inline int eng_struct_ref(ENGINE *e)
+{
+ int res;
+
+ CRYPTO_GET_REF(&e->struct_ref, &res);
+ return res;
+}
+
#endif /* OSSL_CRYPTO_ENGINE_ENG_LOCAL_H */
if (fstr.e != NULL) {
int ref;
- if (!CRYPTO_UP_REF(&fstr.e->struct_ref, &ref, fstr.e->refcnt_lock)) {
+ if (!CRYPTO_UP_REF(&fstr.e->struct_ref, &ref)) {
CRYPTO_THREAD_unlock(global_engine_lock);
ERR_raise(ERR_LIB_ENGINE, ERR_R_CRYPTO_LIB);
return NULL;