diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2009-10-27 17:41:58 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2009-10-27 17:41:58 (GMT) |
commit | dd62966a5fbc502a0e8d91ca3a7de843f1800d99 (patch) | |
tree | e68ae98c2e5c19cbbe5cf0925c6fd841e2a58c4f /Modules/bz2module.c | |
parent | 5098bc944849a7e9a355ae9647d740935893fad1 (diff) | |
download | cpython-dd62966a5fbc502a0e8d91ca3a7de843f1800d99.zip cpython-dd62966a5fbc502a0e8d91ca3a7de843f1800d99.tar.gz cpython-dd62966a5fbc502a0e8d91ca3a7de843f1800d99.tar.bz2 |
Issue #7205: Fix a possible deadlock when using a BZ2File object from several threads at once.
Diffstat (limited to 'Modules/bz2module.c')
-rw-r--r-- | Modules/bz2module.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/Modules/bz2module.c b/Modules/bz2module.c index 045d7b2..c3dae7a 100644 --- a/Modules/bz2module.c +++ b/Modules/bz2module.c @@ -78,7 +78,12 @@ typedef fpos_t Py_off_t; #ifdef WITH_THREAD -#define ACQUIRE_LOCK(obj) PyThread_acquire_lock(obj->lock, 1) +#define ACQUIRE_LOCK(obj) do { \ + if (!PyThread_acquire_lock(obj->lock, 0)) { \ + Py_BEGIN_ALLOW_THREADS \ + PyThread_acquire_lock(obj->lock, 1); \ + Py_END_ALLOW_THREADS \ + } } while(0) #define RELEASE_LOCK(obj) PyThread_release_lock(obj->lock) #else #define ACQUIRE_LOCK(obj) |