diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2009-11-01 11:58:22 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2009-11-01 11:58:22 (GMT) |
commit | e50efaad9f5b17c849ec81eb7c5ae777c887ebb2 (patch) | |
tree | 5931cf621a16034b4932dda02e69935da6258066 /Modules/_io/bufferedio.c | |
parent | d35b8c78990bf3921648c3cb9f186f726c0f13de (diff) | |
download | cpython-e50efaad9f5b17c849ec81eb7c5ae777c887ebb2.zip cpython-e50efaad9f5b17c849ec81eb7c5ae777c887ebb2.tar.gz cpython-e50efaad9f5b17c849ec81eb7c5ae777c887ebb2.tar.bz2 |
Buffered I/O: optimize lock taking in the common non-contended case.
Diffstat (limited to 'Modules/_io/bufferedio.c')
-rw-r--r-- | Modules/_io/bufferedio.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/Modules/_io/bufferedio.c b/Modules/_io/bufferedio.c index 040f3bf..9aa7d4b 100644 --- a/Modules/_io/bufferedio.c +++ b/Modules/_io/bufferedio.c @@ -260,9 +260,11 @@ typedef struct { #ifdef WITH_THREAD #define ENTER_BUFFERED(self) \ - Py_BEGIN_ALLOW_THREADS \ - PyThread_acquire_lock(self->lock, 1); \ - Py_END_ALLOW_THREADS + if (!PyThread_acquire_lock(self->lock, 0)) { \ + Py_BEGIN_ALLOW_THREADS \ + PyThread_acquire_lock(self->lock, 1); \ + Py_END_ALLOW_THREADS \ + } #define LEAVE_BUFFERED(self) \ PyThread_release_lock(self->lock); |