提交 c74471d2 编写于 作者: A Alessandro Ghedini 提交者: Rich Salz

Convert CRYPTO_LOCK_DSO to new multi-threading API

Reviewed-by: NMatt Caswell <matt@openssl.org>
Reviewed-by: NRich Salz <rsalz@openssl.org>
上级 d188a536
......@@ -120,12 +120,20 @@ DSO *DSO_new_method(DSO_METHOD *meth)
else
ret->meth = meth;
ret->references = 1;
if ((ret->meth->init != NULL) && !ret->meth->init(ret)) {
ret->lock = CRYPTO_THREAD_lock_new();
if (ret->lock == NULL) {
sk_void_free(ret->meth_data);
OPENSSL_free(ret);
return NULL;
}
if ((ret->meth->init != NULL) && !ret->meth->init(ret)) {
DSO_free(ret);
ret = NULL;
}
return (ret);
return ret;
}
int DSO_free(DSO *dso)
......@@ -135,27 +143,30 @@ int DSO_free(DSO *dso)
if (dso == NULL)
return (1);
i = CRYPTO_add(&dso->references, -1, CRYPTO_LOCK_DSO);
if (CRYPTO_atomic_add(&dso->references, -1, &i, dso->lock) <= 0)
return 0;
REF_PRINT_COUNT("DSO", dso);
if (i > 0)
return (1);
return 1;
REF_ASSERT_ISNT(i < 0);
if ((dso->meth->dso_unload != NULL) && !dso->meth->dso_unload(dso)) {
DSOerr(DSO_F_DSO_FREE, DSO_R_UNLOAD_FAILED);
return (0);
return 0;
}
if ((dso->meth->finish != NULL) && !dso->meth->finish(dso)) {
DSOerr(DSO_F_DSO_FREE, DSO_R_FINISH_FAILED);
return (0);
return 0;
}
sk_void_free(dso->meth_data);
OPENSSL_free(dso->filename);
OPENSSL_free(dso->loaded_filename);
CRYPTO_THREAD_lock_free(dso->lock);
OPENSSL_free(dso);
return (1);
return 1;
}
int DSO_flags(DSO *dso)
......@@ -165,13 +176,19 @@ int DSO_flags(DSO *dso)
int DSO_up_ref(DSO *dso)
{
int i;
if (dso == NULL) {
DSOerr(DSO_F_DSO_UP_REF, ERR_R_PASSED_NULL_PARAMETER);
return (0);
return 0;
}
CRYPTO_add(&dso->references, 1, CRYPTO_LOCK_DSO);
return (1);
if (CRYPTO_atomic_add(&dso->references, 1, &i, dso->lock) <= 0)
return 0;
REF_PRINT_COUNT("DSO", r);
REF_ASSERT_ISNT(i < 2);
return ((i > 1) ? 1 : 0);
}
DSO *DSO_load(DSO *dso, const char *filename, DSO_METHOD *meth, int flags)
......
......@@ -187,7 +187,6 @@ extern "C" {
# define CRYPTO_LOCK_READDIR 24
# define CRYPTO_LOCK_RSA_BLINDING 25
# define CRYPTO_LOCK_MALLOC2 27
# define CRYPTO_LOCK_DSO 28
# define CRYPTO_LOCK_DYNLOCK 29
# define CRYPTO_LOCK_ENGINE 30
# define CRYPTO_LOCK_UI 31
......
......@@ -228,6 +228,7 @@ struct dso_st {
* loaded.
*/
char *loaded_filename;
CRYPTO_RWLOCK *lock;
};
DSO *DSO_new(void);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册