From f572a72c2a481eab488c7e442e8e44b348eb16f0 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Sun, 3 Mar 2019 23:30:02 +1100 Subject: [PATCH] [c-host] windows: added event support --- c-host/windows/platform.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/c-host/windows/platform.c b/c-host/windows/platform.c index f233f764..33b20ccb 100644 --- a/c-host/windows/platform.c +++ b/c-host/windows/platform.c @@ -298,4 +298,43 @@ bool os_joinThread(osThreadHandle * handle, int * resultCode) DEBUG_WINERROR("Unknown failure waiting for thread", GetLastError()); return false; +} + +osEventHandle * os_createEvent() +{ + HANDLE event = CreateEvent(NULL, FALSE, FALSE, NULL); + return (osEventHandle*)event; +} + +void os_freeEvent(osEventHandle * handle) +{ + CloseHandle((HANDLE)handle); +} + +bool os_waitEvent(osEventHandle * handle) +{ + while(true) + { + switch(WaitForSingleObject((HANDLE)handle, INFINITE)) + { + case WAIT_OBJECT_0: + return true; + + case WAIT_ABANDONED: + case WAIT_TIMEOUT: + continue; + + case WAIT_FAILED: + DEBUG_WINERROR("Wait for event failed", GetLastError()); + return false; + } + + DEBUG_ERROR("Unknown wait event return code"); + return false; + } +} + +bool os_signalEvent(osEventHandle * handle) +{ + return SetEvent((HANDLE)handle); } \ No newline at end of file