Skip to content

Commit 88dc924

Browse files
committed
bpo-45429: Address code review
1 parent efe9a4c commit 88dc924

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

Modules/timemodule.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ static PyTypeObject StructTimeType;
413413
#define CREATE_WAITABLE_TIMER_HIGH_RESOLUTION 0x00000002
414414
#endif
415415

416-
static DWORD timer_flags = CREATE_WAITABLE_TIMER_HIGH_RESOLUTION;
416+
static DWORD timer_flags = 0x00000003;
417417
#endif
418418

419419
static PyObject *
@@ -2025,13 +2025,19 @@ time_exec(PyObject *module)
20252025
#endif
20262026

20272027
#if defined(MS_WINDOWS)
2028-
HANDLE timer = CreateWaitableTimerExW(NULL, NULL, timer_flags, TIMER_ALL_ACCESS);
2029-
if (timer == NULL) {
2030-
// CREATE_WAITABLE_TIMER_HIGH_RESOLUTION is not supported.
2031-
timer_flags = 0;
2032-
}
2033-
else {
2034-
CloseHandle(timer);
2028+
if (timer_flags == 0x00000003) {
2029+
DWORD test_flags = CREATE_WAITABLE_TIMER_HIGH_RESOLUTION;
2030+
HANDLE timer = CreateWaitableTimerExW(NULL, NULL, test_flags,
2031+
TIMER_ALL_ACCESS);
2032+
if (timer == NULL) {
2033+
// CREATE_WAITABLE_TIMER_HIGH_RESOLUTION is not supported.
2034+
timer_flags = 0;
2035+
}
2036+
else {
2037+
// CREATE_WAITABLE_TIMER_HIGH_RESOLUTION is supported.
2038+
timer_flags = CREATE_WAITABLE_TIMER_HIGH_RESOLUTION;
2039+
CloseHandle(timer);
2040+
}
20352041
}
20362042
#endif
20372043

@@ -2168,7 +2174,8 @@ pysleep(_PyTime_t timeout)
21682174
// SetWaitableTimer(): a negative due time indicates relative time
21692175
relative_timeout.QuadPart = -timeout_100ns;
21702176

2171-
HANDLE timer = CreateWaitableTimerExW(NULL, NULL, timer_flags, TIMER_ALL_ACCESS);
2177+
HANDLE timer = CreateWaitableTimerExW(NULL, NULL, timer_flags,
2178+
TIMER_ALL_ACCESS);
21722179
if (timer == NULL) {
21732180
PyErr_SetFromWindowsErr(0);
21742181
return -1;

0 commit comments

Comments
 (0)