]> granicus.if.org Git - python/commitdiff
Issue #11408: In threading.Lock.acquire(), only call gettimeofday() when
authorAntoine Pitrou <solipsis@pitrou.net>
Sun, 6 Mar 2011 07:40:35 +0000 (08:40 +0100)
committerAntoine Pitrou <solipsis@pitrou.net>
Sun, 6 Mar 2011 07:40:35 +0000 (08:40 +0100)
really necessary.  Patch by Charles-François Natali.

Misc/NEWS
Modules/_threadmodule.c

index 11708b7b048fc1dd86ac6953ddf56ff33b8517b2..0f741448f241b97d38a2c379ddb45455992cf268 100644 (file)
--- 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.
index 14ed55e31b6e26874c02935f68d310e0c05df9c3..57d08d369ee7862dcaf841f8ae8c3cdf60de63c7 100644 (file)
@@ -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));