From fe7dac56f0521cfc8a6af44fd690f95cde06a194 Mon Sep 17 00:00:00 2001 From: henderkes Date: Thu, 23 Apr 2026 19:47:10 +0700 Subject: [PATCH] windows: make usleep() alertable so APCs can interrupt it --- win32/time.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/win32/time.c b/win32/time.c index ac1abbc9e9c7b..7c7c6c4205b96 100644 --- a/win32/time.c +++ b/win32/time.c @@ -67,13 +67,19 @@ PHPAPI int usleep(unsigned int useconds) {/*{{{*/ HANDLE timer; LARGE_INTEGER due; + DWORD wait_result; due.QuadPart = -(10 * (__int64)useconds); timer = CreateWaitableTimer(NULL, TRUE, NULL); SetWaitableTimer(timer, &due, 0, NULL, NULL, 0); - WaitForSingleObject(timer, INFINITE); + /* Alertable wait so queued APCs can interrupt it */ + wait_result = WaitForSingleObjectEx(timer, INFINITE, TRUE); CloseHandle(timer); + if (wait_result == WAIT_IO_COMPLETION) { + errno = EINTR; + return -1; + } return 0; }/*}}}*/