Message403703
It's up to the core devs whether or not Python should try to use a high-resolution timer, which is currently undocumented in the Windows API and implemented only in recent releases of Windows 10 and 11. But if this does get supported, the code should fall back on creating a normal timer if CREATE_WAITABLE_TIMER_HIGH_RESOLUTION makes the call fail. For example:
#ifndef CREATE_WAITABLE_TIMER_HIGH_RESOLUTION
#define CREATE_WAITABLE_TIMER_HIGH_RESOLUTION 0x00000002
#endif
LARGE_INTEGER relative_timeout;
// No need to check for integer overflow, both types are signed
assert(sizeof(relative_timeout) == sizeof(timeout_100ns));
// SetWaitableTimerEx(): a negative due time is relative
relative_timeout.QuadPart = -timeout_100ns;
DWORD flags = CREATE_WAITABLE_TIMER_HIGH_RESOLUTION;
create_timer:
HANDLE timer = CreateWaitableTimerExW(NULL, NULL, flags, TIMER_ALL_ACCESS);
if (timer == NULL)
{
if (flags && GetLastError() == ERROR_INVALID_PARAMETER) {
// CREATE_WAITABLE_TIMER_HIGH_RESOLUTION is not supported.
flags = 0;
goto create_timer;
}
PyErr_SetFromWindowsErr(0);
return -1;
}
if (!SetWaitableTimerEx(timer, &relative_timeout,
0, // no period; the timer is signaled once
NULL, NULL, // no completion routine
NULL, // no wake context; do not resume from suspend
0)) // no tolerable delay for timer coalescing
{
PyErr_SetFromWindowsErr(0);
goto error;
} |
|
Date |
User |
Action |
Args |
2021-10-11 23:26:20 | eryksun | set | recipients:
+ eryksun, paul.moore, vstinner, tim.golden, zach.ware, steve.dower, corona10 |
2021-10-11 23:26:20 | eryksun | set | messageid: <1633994780.22.0.3439432049.issue45429@roundup.psfhosted.org> |
2021-10-11 23:26:20 | eryksun | link | issue45429 messages |
2021-10-11 23:26:20 | eryksun | create | |
|