diff --git a/dtls/openssl.py b/dtls/openssl.py index bea985c..c48ea60 100644 --- a/dtls/openssl.py +++ b/dtls/openssl.py @@ -486,6 +486,7 @@ map(lambda x: _make_function(*x), ( ("SSLeay_version", libcrypto, ((c_char_p, "ret"), (c_int, "t"))), ("CRYPTO_set_locking_callback", libcrypto, ((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"),)), ("DTLSv1_server_method", libssl, ((DTLSv1Method, "ret"),)), ("DTLSv1_client_method", libssl, ((DTLSv1Method, "ret"),)), diff --git a/dtls/tlock.py b/dtls/tlock.py index 4aea6f8..1771dc1 100644 --- a/dtls/tlock.py +++ b/dtls/tlock.py @@ -21,6 +21,10 @@ DO_DEBUG_LOG = False def tlock_init(): if not globals().has_key("threading"): 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 num_locks = CRYPTO_num_locks() _locks = tuple(threading.Lock() for _ in range(num_locks))