[issue4751] Patch for better thread support in hashlib
STINNER Victor
report at bugs.python.org
Sat Dec 27 00:18:30 CET 2008
STINNER Victor <victor.stinner at haypocalc.com> added the comment:
New version of ebfe's patch:
- ENTER/LEAVE_HASHLIB:
* don't touch GIL in ENTER_HASHLIB (it's useless)
* add mandatory argument (explicit use of "self")
- EVP_hash():
* restore Py_SAFE_DOWNCAST
* simplify the code: always use the while() instead of if+while
* use "while (0 < len)" to skip zero or negative value (even if
pitrou told me that len should not be negative)
- EVP_dealloc(): free the lock before the context
- release the GIL for all calls to EVP_hash()
- use the context lock in EVP_copy() and EVP_get_digest_size() to
protect self
- don't use the context lock in EVP_repr() (useless because we don't
read OpenSSL context)
- fix the indentation of the code (replace tab by spaces)
Some rules for ENTER/LEAVE_HASHLIB:
* it is only needed to protect the context attribute (eg. name
doesn't need to be protected by the lock)
* it doesn't touch the GIL: use an explicit call to
Py_BEGIN_ALLOW_THREADS/Py_END_ALLOW_THREADS
About the GIL:
* EVP_DigestInit() and EVP_MD_CTX_copy() are consired fast enough to
no release the GIL
* The GIL is released for the slowest function: EVP_DigestUpdate()
(called in our EVP_hash() function)
Added file: http://bugs.python.org/file12459/hashopenssl_threads-2.diff
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4751>
_______________________________________
More information about the Python-bugs-list
mailing list