From: Antoine Pitrou Date: Sun, 1 Nov 2009 11:58:22 +0000 (+0000) Subject: Buffered I/O: optimize lock taking in the common non-contended case. X-Git-Tag: v2.7a1~175 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e50efaad9f5b17c849ec81eb7c5ae777c887ebb2;p=thirdparty%2FPython%2Fcpython.git Buffered I/O: optimize lock taking in the common non-contended case. --- diff --git a/Modules/_io/bufferedio.c b/Modules/_io/bufferedio.c index 040f3bf9e76d..9aa7d4b8b8c4 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);