2014-01-25 03:08:06 +04:00
|
|
|
|
|
|
|
#include <winpr/crt.h>
|
|
|
|
#include <winpr/synch.h>
|
2014-01-25 07:44:23 +04:00
|
|
|
#include <winpr/sysinfo.h>
|
2014-01-25 03:08:06 +04:00
|
|
|
|
2014-01-25 07:44:23 +04:00
|
|
|
static int g_Count = 0;
|
|
|
|
static HANDLE g_Event = NULL;
|
|
|
|
|
|
|
|
struct apc_data
|
|
|
|
{
|
|
|
|
UINT32 StartTime;
|
|
|
|
};
|
|
|
|
typedef struct apc_data APC_DATA;
|
2014-01-25 03:08:06 +04:00
|
|
|
|
2018-03-08 15:46:46 +03:00
|
|
|
static VOID CALLBACK TimerAPCProc(LPVOID lpArg, DWORD dwTimerLowValue, DWORD dwTimerHighValue)
|
2014-01-25 03:08:06 +04:00
|
|
|
{
|
2014-01-25 07:44:23 +04:00
|
|
|
APC_DATA* apcData;
|
|
|
|
UINT32 CurrentTime = GetTickCount();
|
2019-02-08 11:18:16 +03:00
|
|
|
WINPR_UNUSED(dwTimerLowValue);
|
|
|
|
WINPR_UNUSED(dwTimerHighValue);
|
2014-01-25 03:08:06 +04:00
|
|
|
|
|
|
|
if (!lpArg)
|
|
|
|
return;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
apcData = (APC_DATA*)lpArg;
|
|
|
|
printf("TimerAPCProc: time: %" PRIu32 "\n", CurrentTime - apcData->StartTime);
|
2014-01-25 07:44:23 +04:00
|
|
|
g_Count++;
|
2014-01-25 03:08:06 +04:00
|
|
|
|
2014-01-25 07:44:23 +04:00
|
|
|
if (g_Count >= 5)
|
|
|
|
{
|
|
|
|
SetEvent(g_Event);
|
|
|
|
}
|
2014-01-25 03:08:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int TestSynchWaitableTimerAPC(int argc, char* argv[])
|
|
|
|
{
|
2014-11-17 01:10:33 +03:00
|
|
|
int status = -1;
|
2021-03-24 20:32:43 +03:00
|
|
|
DWORD rc;
|
2014-11-17 01:10:33 +03:00
|
|
|
HANDLE hTimer = NULL;
|
2014-01-25 03:08:06 +04:00
|
|
|
BOOL bSuccess;
|
2014-01-25 07:44:23 +04:00
|
|
|
LARGE_INTEGER due;
|
2019-02-08 11:18:16 +03:00
|
|
|
APC_DATA apcData = { 0 };
|
|
|
|
WINPR_UNUSED(argc);
|
|
|
|
WINPR_UNUSED(argv);
|
2014-01-25 07:44:23 +04:00
|
|
|
g_Event = CreateEvent(NULL, TRUE, FALSE, NULL);
|
2019-02-08 11:18:16 +03:00
|
|
|
|
2015-04-28 18:00:41 +03:00
|
|
|
if (!g_Event)
|
|
|
|
{
|
|
|
|
printf("Failed to create event\n");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2014-01-25 03:08:06 +04:00
|
|
|
hTimer = CreateWaitableTimer(NULL, FALSE, NULL);
|
|
|
|
if (!hTimer)
|
2014-11-17 01:10:33 +03:00
|
|
|
goto cleanup;
|
2014-01-25 03:08:06 +04:00
|
|
|
|
2021-06-02 16:46:27 +03:00
|
|
|
due.QuadPart = -1000 * 100LL; /* 0.1 seconds */
|
2019-02-08 11:18:16 +03:00
|
|
|
apcData.StartTime = GetTickCount();
|
2021-06-02 16:46:27 +03:00
|
|
|
bSuccess = SetWaitableTimer(hTimer, &due, 10, TimerAPCProc, &apcData, FALSE);
|
2014-01-25 03:08:06 +04:00
|
|
|
|
|
|
|
if (!bSuccess)
|
2014-11-17 01:10:33 +03:00
|
|
|
goto cleanup;
|
2014-01-25 03:08:06 +04:00
|
|
|
|
2021-06-02 16:46:27 +03:00
|
|
|
/* nothing shall happen after 0.12 second, because thread is not in alertable state */
|
|
|
|
rc = WaitForSingleObject(g_Event, 120);
|
2021-03-24 20:32:43 +03:00
|
|
|
if (rc != WAIT_TIMEOUT)
|
|
|
|
goto cleanup;
|
2016-05-24 23:33:27 +03:00
|
|
|
|
2019-02-08 11:18:16 +03:00
|
|
|
for (;;)
|
2014-01-25 03:08:06 +04:00
|
|
|
{
|
2016-05-24 23:33:27 +03:00
|
|
|
rc = WaitForSingleObjectEx(g_Event, INFINITE, TRUE);
|
|
|
|
if (rc == WAIT_OBJECT_0)
|
|
|
|
break;
|
|
|
|
|
2021-03-16 17:15:13 +03:00
|
|
|
if (rc == WAIT_IO_COMPLETION)
|
2016-05-24 23:33:27 +03:00
|
|
|
continue;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
printf("Failed to wait for completion event (%" PRIu32 ")\n", GetLastError());
|
2014-11-17 01:10:33 +03:00
|
|
|
goto cleanup;
|
2014-01-25 03:08:06 +04:00
|
|
|
}
|
|
|
|
|
2014-11-17 01:10:33 +03:00
|
|
|
status = 0;
|
|
|
|
cleanup:
|
2019-02-08 11:18:16 +03:00
|
|
|
|
2014-11-17 01:52:22 +03:00
|
|
|
if (hTimer)
|
2014-11-17 01:10:33 +03:00
|
|
|
CloseHandle(hTimer);
|
2019-02-08 11:18:16 +03:00
|
|
|
|
2014-11-17 01:10:33 +03:00
|
|
|
if (g_Event)
|
|
|
|
CloseHandle(g_Event);
|
2014-01-25 03:08:06 +04:00
|
|
|
|
2014-11-17 01:10:33 +03:00
|
|
|
return status;
|
2014-01-25 03:08:06 +04:00
|
|
|
}
|