2013-07-29 21:07:39 +04:00
|
|
|
|
|
|
|
#include <winpr/crt.h>
|
|
|
|
#include <winpr/synch.h>
|
|
|
|
|
|
|
|
int TestSynchWaitableTimer(int argc, char* argv[])
|
|
|
|
{
|
2013-09-19 22:17:00 +04:00
|
|
|
DWORD status;
|
2013-07-29 21:07:39 +04:00
|
|
|
HANDLE timer;
|
|
|
|
LONG period;
|
|
|
|
LARGE_INTEGER due;
|
2016-06-07 18:20:56 +03:00
|
|
|
int result = -1;
|
2019-02-08 11:18:16 +03:00
|
|
|
WINPR_UNUSED(argc);
|
|
|
|
WINPR_UNUSED(argv);
|
2013-09-19 22:17:00 +04:00
|
|
|
timer = CreateWaitableTimer(NULL, FALSE, NULL);
|
2013-07-29 21:07:39 +04:00
|
|
|
|
|
|
|
if (!timer)
|
|
|
|
{
|
|
|
|
printf("CreateWaitableTimer failure\n");
|
2016-06-07 18:20:56 +03:00
|
|
|
goto out;
|
2013-07-29 21:07:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
due.QuadPart = -15000000LL; /* 1.5 seconds */
|
|
|
|
|
|
|
|
if (!SetWaitableTimer(timer, &due, 0, NULL, NULL, 0))
|
|
|
|
{
|
|
|
|
printf("SetWaitableTimer failure\n");
|
2016-06-07 18:20:56 +03:00
|
|
|
goto out;
|
2013-07-29 21:07:39 +04:00
|
|
|
}
|
|
|
|
|
2013-09-19 22:17:00 +04:00
|
|
|
status = WaitForSingleObject(timer, INFINITE);
|
|
|
|
|
|
|
|
if (status != WAIT_OBJECT_0)
|
2013-07-29 21:07:39 +04:00
|
|
|
{
|
|
|
|
printf("WaitForSingleObject(timer, INFINITE) failure\n");
|
2016-06-07 18:20:56 +03:00
|
|
|
goto out;
|
2013-07-29 21:07:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
printf("Timer Signaled\n");
|
2013-09-19 22:17:00 +04:00
|
|
|
status = WaitForSingleObject(timer, 2000);
|
|
|
|
|
|
|
|
if (status != WAIT_TIMEOUT)
|
2013-07-29 21:07:39 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
printf("WaitForSingleObject(timer, 2000) failure: Actual: 0x%08" PRIX32
|
|
|
|
", Expected: 0x%08X\n",
|
2018-03-08 15:46:46 +03:00
|
|
|
status, WAIT_TIMEOUT);
|
2016-06-07 18:20:56 +03:00
|
|
|
goto out;
|
2013-07-29 21:07:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
due.QuadPart = 0;
|
|
|
|
period = 1200; /* 1.2 seconds */
|
|
|
|
|
|
|
|
if (!SetWaitableTimer(timer, &due, period, NULL, NULL, 0))
|
|
|
|
{
|
|
|
|
printf("SetWaitableTimer failure\n");
|
2016-06-07 18:20:56 +03:00
|
|
|
goto out;
|
2013-07-29 21:07:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (WaitForSingleObject(timer, INFINITE) != WAIT_OBJECT_0)
|
|
|
|
{
|
|
|
|
printf("WaitForSingleObject(timer, INFINITE) failure\n");
|
2016-06-07 18:20:56 +03:00
|
|
|
goto out;
|
2013-07-29 21:07:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
printf("Timer Signaled\n");
|
|
|
|
|
2018-03-08 15:46:46 +03:00
|
|
|
if (!SetWaitableTimer(timer, &due, period, NULL, NULL, 0))
|
|
|
|
{
|
|
|
|
printf("SetWaitableTimer failure\n");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2013-07-29 21:07:39 +04:00
|
|
|
if (WaitForMultipleObjects(1, &timer, FALSE, INFINITE) != WAIT_OBJECT_0)
|
|
|
|
{
|
|
|
|
printf("WaitForMultipleObjects(timer, INFINITE) failure\n");
|
2016-06-07 18:20:56 +03:00
|
|
|
goto out;
|
2013-07-29 21:07:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
printf("Timer Signaled\n");
|
2016-06-07 18:20:56 +03:00
|
|
|
result = 0;
|
|
|
|
out:
|
2013-07-29 21:07:39 +04:00
|
|
|
CloseHandle(timer);
|
2016-06-07 18:20:56 +03:00
|
|
|
return result;
|
2013-07-29 21:07:39 +04:00
|
|
|
}
|