Skip to content

Commit 125d5c8

Browse files
committed
Issue #11408: In threading.Lock.acquire(), only call gettimeofday() when
really necessary. Patch by Charles-François Natali.
1 parent f874deb commit 125d5c8

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ Core and Builtins
5555
Library
5656
-------
5757

58+
- Issue #11408: In threading.Lock.acquire(), only call gettimeofday() when
59+
really necessary. Patch by Charles-François Natali.
60+
5861
- Issue #11391: Writing to a mmap object created with
5962
``mmap.PROT_READ|mmap.PROT_EXEC`` would segfault instead of raising a
6063
TypeError. Patch by Charles-François Natali.

Modules/_threadmodule.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ acquire_timed(PyThread_type_lock lock, PY_TIMEOUT_T microseconds)
5454
_PyTime_timeval endtime;
5555

5656

57-
_PyTime_gettimeofday(&endtime);
5857
if (microseconds > 0) {
58+
_PyTime_gettimeofday(&endtime);
5959
endtime.tv_sec += microseconds / (1000 * 1000);
6060
endtime.tv_usec += microseconds % (1000 * 1000);
6161
}
@@ -76,7 +76,7 @@ acquire_timed(PyThread_type_lock lock, PY_TIMEOUT_T microseconds)
7676

7777
/* If we're using a timeout, recompute the timeout after processing
7878
* signals, since those can take time. */
79-
if (microseconds >= 0) {
79+
if (microseconds > 0) {
8080
_PyTime_gettimeofday(&curtime);
8181
microseconds = ((endtime.tv_sec - curtime.tv_sec) * 1000000 +
8282
(endtime.tv_usec - curtime.tv_usec));

0 commit comments

Comments
 (0)