1 | // Licensed to the .NET Foundation under one or more agreements. |
2 | // The .NET Foundation licenses this file to you under the MIT license. |
3 | // See the LICENSE file in the project root for more information. |
4 | |
5 | /*============================================================================= |
6 | ** |
7 | ** Source: test4.c |
8 | ** |
9 | ** Dependencies: PAL_Initialize |
10 | ** PAL_Terminate |
11 | ** GetCurrentThread |
12 | ** SleepEx |
13 | ** |
14 | ** Purpose: |
15 | ** |
16 | ** Test to ensure proper operation of the QueueUserAPC() |
17 | ** API by trying to queue APC functions on the current |
18 | ** thread. |
19 | ** |
20 | ** |
21 | **===========================================================================*/ |
22 | #include <palsuite.h> |
23 | |
24 | |
25 | static BOOL bAPCExecuted = FALSE; |
26 | |
27 | VOID PALAPI APCFunc( ULONG_PTR dwParam ) |
28 | { |
29 | bAPCExecuted = TRUE; |
30 | } |
31 | |
32 | int __cdecl main( int argc, char **argv ) |
33 | |
34 | { |
35 | /* local variables */ |
36 | HANDLE hThread = NULL; |
37 | DWORD ret; |
38 | |
39 | /* PAL initialization */ |
40 | if( (PAL_Initialize(argc, argv)) != 0 ) |
41 | { |
42 | return( FAIL ); |
43 | } |
44 | |
45 | /* get the current thread */ |
46 | hThread = GetCurrentThread(); |
47 | ret = QueueUserAPC( APCFunc, hThread, 0 ); |
48 | if( ret == 0 ) |
49 | { |
50 | Fail( "ERROR:%lu:QueueUserAPC call failed\n" , GetLastError() ); |
51 | } |
52 | |
53 | /* call SleepEx() to put the thread in an alertable state */ |
54 | ret = SleepEx( 2000, TRUE ); |
55 | if( ret != WAIT_IO_COMPLETION ) |
56 | { |
57 | Fail( "ERROR:Expected sleep to return WAIT_IO_COMPLETION, got %lu\n" , |
58 | ret ); |
59 | } |
60 | |
61 | /* check that the APC function was executed */ |
62 | if( bAPCExecuted == FALSE ) |
63 | { |
64 | Fail( "ERROR:APC function was not executed\n" ); |
65 | } |
66 | |
67 | /* PAL termination */ |
68 | PAL_Terminate(); |
69 | |
70 | /* return success */ |
71 | return PASS; |
72 | } |
73 | |