summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Paul Calderone <exarkun@twistedmatrix.com>2014-01-01 12:21:34 -0500
committerJean-Paul Calderone <exarkun@twistedmatrix.com>2014-01-01 12:21:34 -0500
commit6bb4089734fb264e90912608baa05a57085f0126 (patch)
tree4d6d4581e6d1559dda2339c6f7f442c4201a64c4
parenta5fb4e02b11ff6618acb2289bcf04f6cb242272e (diff)
downloadpyopenssl-6bb4089734fb264e90912608baa05a57085f0126.tar.gz
try adding some thread initialization logic
this includes a real version and a cheater version. it may be necessary to use the cheater version as the _ssl module in the stdlib is just going to trample whatever we try to do anyway.
-rw-r--r--OpenSSL/crypto.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/OpenSSL/crypto.py b/OpenSSL/crypto.py
index 3178b5a..0c78b31 100644
--- a/OpenSSL/crypto.py
+++ b/OpenSSL/crypto.py
@@ -2227,3 +2227,33 @@ def load_pkcs12(buffer, passphrase):
pkcs12._cacerts = pycacerts
pkcs12._friendlyname = friendlyname
return pkcs12
+
+
+def _initialize_openssl_threads(get_ident, Lock):
+ import _ssl
+ return
+
+ locks = list(Lock() for n in range(_lib.CRYPTO_num_locks()))
+
+ def locking_function(mode, index, filename, line):
+ if mode & _lib.CRYPTO_LOCK:
+ locks[index].acquire()
+ else:
+ locks[index].release()
+
+ _lib.CRYPTO_set_id_callback(
+ _ffi.callback("unsigned long (*)(void)", get_ident))
+
+ _lib.CRYPTO_set_locking_callback(
+ _ffi.callback(
+ "void (*)(int, int, const char*, int)", locking_function))
+
+
+try:
+ from thread import get_ident
+ from threading import Lock
+except ImportError:
+ pass
+else:
+ _initialize_openssl_threads(get_ident, Lock)
+ del get_ident, Lock