aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatarLibravatar daurnimator <quae@daurnimator.com> 2017-08-31 02:40:47 +1000
committerLibravatarLibravatar daurnimator <quae@daurnimator.com> 2017-08-31 02:40:47 +1000
commite917b0805fc9374b06cfd93204aefe5d3375d8d4 (patch)
tree81c4ff783958e648a62ffec6f5e4ba07999fa0ec
parentd36d78f74c537c317528bc68ea734997054c6411 (diff)
parent13b82f5706ee9f430203c2559250056e5e12de72 (diff)
downloadluaossl-e917b0805fc9374b06cfd93204aefe5d3375d8d4.tar.gz
luaossl-e917b0805fc9374b06cfd93204aefe5d3375d8d4.tar.bz2
luaossl-e917b0805fc9374b06cfd93204aefe5d3375d8d4.zip
Merge remote-tracking branch 'daurnimator/less-locks'
-rw-r--r--src/openssl.c46
1 files changed, 14 insertions, 32 deletions
diff --git a/src/openssl.c b/src/openssl.c
index cea38a5..1b11207 100644
--- a/src/openssl.c
+++ b/src/openssl.c
@@ -1318,17 +1318,14 @@ static const EVP_MD *auxL_optdigest(lua_State *L, int index, EVP_PKEY *key, cons
* Prevent loader from unlinking us if we've registered a callback with
* OpenSSL by taking another reference to ourselves.
*/
+/* dl_anchor must not be called from multiple threads at once */
static int dl_anchor(void) {
#if HAVE_DLADDR
extern int luaopen__openssl(lua_State *);
- static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
static void *anchor;
Dl_info info;
int error = 0;
- if ((error = pthread_mutex_lock(&mutex)))
- return error;
-
if (anchor)
goto epilog;
@@ -1338,8 +1335,6 @@ static int dl_anchor(void) {
if (!(anchor = dlopen(info.dli_fname, RTLD_NOW|RTLD_LOCAL)))
goto dlerr;
epilog:
- (void)pthread_mutex_unlock(&mutex);
-
return error;
dlerr:
error = auxL_EDYLD;
@@ -1910,14 +1905,11 @@ static int compat_X509_up_ref(X509 *crt) {
*/
#endif
+/* compat_init must not be called from multiple threads at once */
static int compat_init(void) {
- static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
static int store_index = -1, ssl_ctx_index = -1, done;
int error = 0;
- if ((error = pthread_mutex_lock(&mutex)))
- return error;
-
if (done)
goto epilog;
@@ -1988,8 +1980,6 @@ epilog:
compat.tmp.store = NULL;
}
- (void)pthread_mutex_unlock(&mutex);
-
return error;
sslerr:
error = auxL_EOPENSSL;
@@ -2115,15 +2105,12 @@ static void ex_onfree(void *parent NOTUSED, void *_data, CRYPTO_EX_DATA *ad NOTU
free(data);
} /* ex_onfree() */
+/* ex_init must not be called from multiple threads at once */
static int ex_init(void) {
- static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
static int done;
struct ex_type *type;
int error = 0;
- if ((error = pthread_mutex_lock(&mutex)))
- return error;
-
if (done)
goto epilog;
@@ -2144,8 +2131,6 @@ static int ex_init(void) {
done = 1;
epilog:
- (void)pthread_mutex_unlock(&mutex);
-
return error;
sslerr:
error = auxL_EOPENSSL;
@@ -10435,14 +10420,11 @@ static unsigned long mt_gettid(void) {
#endif
} /* mt_gettid() */
+/* mt_init must not be called from multiple threads at once */
static int mt_init(void) {
- static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
static int done, bound;
int error = 0;
- if ((error = pthread_mutex_lock(&mutex)))
- return error;
-
if (done)
goto epilog;
@@ -10485,8 +10467,6 @@ static int mt_init(void) {
done = 1;
epilog:
- pthread_mutex_unlock(&mutex);
-
return error;
} /* mt_init() */
@@ -10496,12 +10476,11 @@ static void initall(lua_State *L) {
static int initssl;
int error;
- if ((error = mt_init()))
- auxL_error(L, error, "openssl.init");
-
pthread_mutex_lock(&mutex);
- if (!initssl) {
+ error = mt_init();
+
+ if (!error && !initssl) {
initssl = 1;
SSL_load_error_strings();
@@ -10515,12 +10494,15 @@ static void initall(lua_State *L) {
OPENSSL_config(NULL);
}
- pthread_mutex_unlock(&mutex);
+ if (!error)
+ error = compat_init();
- if ((error = compat_init()))
- auxL_error(L, error, "openssl.init");
+ if (!error)
+ error = ex_init();
+
+ pthread_mutex_unlock(&mutex);
- if ((error = ex_init()))
+ if (error)
auxL_error(L, error, "openssl.init");
ex_newstate(L);