From 125d5c877056db5d6487f21124064bc85283843a Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Sun, 6 Mar 2011 08:40:35 +0100 Subject: [PATCH] =?utf8?q?Issue=20#11408:=20In=20threading.Lock.acquire(),?= =?utf8?q?=20only=20call=20gettimeofday()=20when=20really=20necessary.=20?= =?utf8?q?=20Patch=20by=20Charles-Fran=C3=A7ois=20Natali.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- Misc/NEWS | 3 +++ Modules/_threadmodule.c | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS index 11708b7b04..0f741448f2 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -55,6 +55,9 @@ Core and Builtins Library ------- +- Issue #11408: In threading.Lock.acquire(), only call gettimeofday() when + really necessary. Patch by Charles-François Natali. + - Issue #11391: Writing to a mmap object created with ``mmap.PROT_READ|mmap.PROT_EXEC`` would segfault instead of raising a TypeError. Patch by Charles-François Natali. diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c index 14ed55e31b..57d08d369e 100644 --- a/Modules/_threadmodule.c +++ b/Modules/_threadmodule.c @@ -54,8 +54,8 @@ acquire_timed(PyThread_type_lock lock, PY_TIMEOUT_T microseconds) _PyTime_timeval endtime; - _PyTime_gettimeofday(&endtime); if (microseconds > 0) { + _PyTime_gettimeofday(&endtime); endtime.tv_sec += microseconds / (1000 * 1000); endtime.tv_usec += microseconds % (1000 * 1000); } @@ -76,7 +76,7 @@ acquire_timed(PyThread_type_lock lock, PY_TIMEOUT_T microseconds) /* If we're using a timeout, recompute the timeout after processing * signals, since those can take time. */ - if (microseconds >= 0) { + if (microseconds > 0) { _PyTime_gettimeofday(&curtime); microseconds = ((endtime.tv_sec - curtime.tv_sec) * 1000000 + (endtime.tv_usec - curtime.tv_usec)); -- 2.50.1