Use ssl module locking when available
Thread locking callbacks into the interpreter impose considerable overhead. The standard library's ssl module registers its own thread locking and id callback functions. Registration of the latter can be detected by a call to the OpenSSL library. In this case, do not set the Python callback function and therefore keep using the more efficient ssl module functions.incoming
parent
7c6a512f94
commit
5f97e81a69
|
@ -486,6 +486,7 @@ map(lambda x: _make_function(*x), (
|
||||||
("SSLeay_version", libcrypto, ((c_char_p, "ret"), (c_int, "t"))),
|
("SSLeay_version", libcrypto, ((c_char_p, "ret"), (c_int, "t"))),
|
||||||
("CRYPTO_set_locking_callback", libcrypto,
|
("CRYPTO_set_locking_callback", libcrypto,
|
||||||
((None, "ret"), (c_void_p, "func")), False),
|
((None, "ret"), (c_void_p, "func")), False),
|
||||||
|
("CRYPTO_get_id_callback", libcrypto, ((c_void_p, "ret"),), True, None),
|
||||||
("CRYPTO_num_locks", libcrypto, ((c_int, "ret"),)),
|
("CRYPTO_num_locks", libcrypto, ((c_int, "ret"),)),
|
||||||
("DTLSv1_server_method", libssl, ((DTLSv1Method, "ret"),)),
|
("DTLSv1_server_method", libssl, ((DTLSv1Method, "ret"),)),
|
||||||
("DTLSv1_client_method", libssl, ((DTLSv1Method, "ret"),)),
|
("DTLSv1_client_method", libssl, ((DTLSv1Method, "ret"),)),
|
||||||
|
|
|
@ -21,6 +21,10 @@ DO_DEBUG_LOG = False
|
||||||
def tlock_init():
|
def tlock_init():
|
||||||
if not globals().has_key("threading"):
|
if not globals().has_key("threading"):
|
||||||
return # nothing to configure
|
return # nothing to configure
|
||||||
|
# The standard library ssl module's lock implementation is more efficient;
|
||||||
|
# do not override it if it has been established
|
||||||
|
if CRYPTO_get_id_callback():
|
||||||
|
return
|
||||||
global _locks
|
global _locks
|
||||||
num_locks = CRYPTO_num_locks()
|
num_locks = CRYPTO_num_locks()
|
||||||
_locks = tuple(threading.Lock() for _ in range(num_locks))
|
_locks = tuple(threading.Lock() for _ in range(num_locks))
|
||||||
|
|
Loading…
Reference in New Issue