| 1 |
|
| 2 |
#include <winpr/crt.h> |
| 3 |
#include <winpr/synch.h> |
| 4 |
|
| 5 |
int TestSynchWaitableTimer(int argc, char* argv[]) |
| 6 |
{ |
| 7 |
DWORD status = 0; |
| 8 |
HANDLE timer = nullptr; |
| 9 |
LONG period = 0; |
| 10 |
LARGE_INTEGER due = WINPR_C_ARRAY_INIT; |
| 11 |
int result = -1; |
| 12 |
WINPR_UNUSED(argc); |
| 13 |
WINPR_UNUSED(argv); |
| 14 |
timer = CreateWaitableTimer(nullptr, FALSE, nullptr); |
| 15 |
|
| 16 |
if (!timer) |
| 17 |
{ |
| 18 |
printf("CreateWaitableTimer failure\n"); |
| 19 |
goto out; |
| 20 |
} |
| 21 |
|
| 22 |
due.QuadPart = -1500000LL; /* 0.15 seconds */ |
| 23 |
|
| 24 |
if (!SetWaitableTimer(timer, &due, 0, nullptr, nullptr, 0)) |
| 25 |
{ |
| 26 |
printf("SetWaitableTimer failure\n"); |
| 27 |
goto out; |
| 28 |
} |
| 29 |
|
| 30 |
status = WaitForSingleObject(timer, INFINITE); |
| 31 |
|
| 32 |
if (status != WAIT_OBJECT_0) |
| 33 |
{ |
| 34 |
printf("WaitForSingleObject(timer, INFINITE) failure\n"); |
| 35 |
goto out; |
| 36 |
} |
| 37 |
|
| 38 |
printf("Timer Signaled\n"); |
| 39 |
status = WaitForSingleObject(timer, 200); |
| 40 |
|
| 41 |
if (status != WAIT_TIMEOUT) |
| 42 |
{ |
| 43 |
printf("WaitForSingleObject(timer, 200) failure: Actual: 0x%08" PRIX32 |
| 44 |
", Expected: 0x%08X\n", |
| 45 |
status, WAIT_TIMEOUT); |
| 46 |
goto out; |
| 47 |
} |
| 48 |
|
| 49 |
due.QuadPart = 0; |
| 50 |
period = 120; /* 0.12 seconds */ |
| 51 |
|
| 52 |
if (!SetWaitableTimer(timer, &due, period, nullptr, nullptr, 0)) |
| 53 |
{ |
| 54 |
printf("SetWaitableTimer failure\n"); |
| 55 |
goto out; |
| 56 |
} |
| 57 |
|
| 58 |
if (WaitForSingleObject(timer, INFINITE) != WAIT_OBJECT_0) |
| 59 |
{ |
| 60 |
printf("WaitForSingleObject(timer, INFINITE) failure\n"); |
| 61 |
goto out; |
| 62 |
} |
| 63 |
|
| 64 |
printf("Timer Signaled\n"); |
| 65 |
|
| 66 |
if (!SetWaitableTimer(timer, &due, period, nullptr, nullptr, 0)) |
| 67 |
{ |
| 68 |
printf("SetWaitableTimer failure\n"); |
| 69 |
goto out; |
| 70 |
} |
| 71 |
|
| 72 |
if (WaitForMultipleObjects(1, &timer, FALSE, INFINITE) != WAIT_OBJECT_0) |
| 73 |
{ |
| 74 |
printf("WaitForMultipleObjects(timer, INFINITE) failure\n"); |
| 75 |
goto out; |
| 76 |
} |
| 77 |
|
| 78 |
printf("Timer Signaled\n"); |
| 79 |
result = 0; |
| 80 |
out: |
| 81 |
(void)CloseHandle(timer); |
| 82 |
return result; |
| 83 |
} |