3 #include <winpr/synch.h>
4 #include <winpr/sysinfo.h>
6 static int g_Count = 0;
7 static HANDLE g_Event = NULL;
13 typedef struct apc_data APC_DATA;
15 static VOID CALLBACK TimerAPCProc(LPVOID lpArg, DWORD dwTimerLowValue, DWORD dwTimerHighValue)
17 APC_DATA* apcData = NULL;
18 UINT32 CurrentTime = GetTickCount();
19 WINPR_UNUSED(dwTimerLowValue);
20 WINPR_UNUSED(dwTimerHighValue);
25 apcData = (APC_DATA*)lpArg;
26 printf(
"TimerAPCProc: time: %" PRIu32
"\n", CurrentTime - apcData->StartTime);
31 (void)SetEvent(g_Event);
35 int TestSynchWaitableTimerAPC(
int argc,
char* argv[])
41 LARGE_INTEGER due = { 0 };
42 APC_DATA apcData = { 0 };
45 g_Event = CreateEvent(NULL, TRUE, FALSE, NULL);
49 printf(
"Failed to create event\n");
53 hTimer = CreateWaitableTimer(NULL, FALSE, NULL);
57 due.QuadPart = -1000 * 100LL;
58 apcData.StartTime = GetTickCount();
59 bSuccess = SetWaitableTimer(hTimer, &due, 10, TimerAPCProc, &apcData, FALSE);
65 rc = WaitForSingleObject(g_Event, 120);
66 if (rc != WAIT_TIMEOUT)
71 rc = WaitForSingleObjectEx(g_Event, INFINITE, TRUE);
72 if (rc == WAIT_OBJECT_0)
75 if (rc == WAIT_IO_COMPLETION)
78 printf(
"Failed to wait for completion event (%" PRIu32
")\n", GetLastError());
86 (void)CloseHandle(hTimer);
89 (void)CloseHandle(g_Event);