Skip to content

Commit b7623c5

Browse files
committed
Async: Handle different GetQueuedCompletionStatusEx behaviour on Windows 10
Fix #15
1 parent 40341b4 commit b7623c5

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Libraries/Async/Internal/AsyncWindows.inl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,21 @@ struct SC::AsyncEventLoop::KernelQueue
189189
OVERLAPPED_ENTRY events[totalNumEvents];
190190
ULONG newEvents = 0;
191191

192-
KernelQueue(Internal&) { memset(events, totalNumEvents, sizeof(events[0])); }
192+
KernelQueue(Internal&) { ::memset(events, 0, totalNumEvents * sizeof(events[0])); }
193193

194194
uint32_t getNumEvents() const { return static_cast<uint32_t>(newEvents); }
195195

196196
[[nodiscard]] AsyncRequest* getAsyncRequest(uint32_t index)
197197
{
198198
OVERLAPPED_ENTRY& event = events[index];
199+
if (event.lpOverlapped == nullptr)
200+
{
201+
// On Windows 10 GetQueuedCompletionStatusEx reports 1 removed entry when called on
202+
// an Completion Port that has nothing scheduled on it.
203+
// This happens for example during first creation of the event loop, with the runNoWait
204+
// that is executed after createSharedWatchers()
205+
return nullptr;
206+
}
199207
return detail::AsyncWinOverlapped::getUserDataFromOverlapped<AsyncRequest>(event.lpOverlapped);
200208
}
201209

0 commit comments

Comments
 (0)