d36c96724f5832478f65f99224ea5dc21b983414
[platform/core/dotnet/diagnostics.git] /
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: InterlockedExchangePointer
8 **
9 ** Purpose: Positive test the InterlockedExchangePointer API.
10 **          Call InterlockedExchangePointer to exchange a pair of
11 **          value
12 **          
13 **
14 **
15 **============================================================*/
16 #include <palsuite.h>
17
18 int __cdecl main(int argc, char *argv[])
19 {
20     int err;
21     int i1 = 10;
22     int i2 = 20;
23     int *pOldValue = &i1;
24     int *pNewValue = &i2;
25     PVOID pReturnValue;
26    
27     /*Initialize the PAL environment*/
28     err = PAL_Initialize(argc, argv);
29     if(0 != err)
30     {
31         return FAIL;
32     }
33
34
35
36     /*
37       Testing
38       =======
39     */
40         
41     pReturnValue = InterlockedExchangePointer((PVOID)&pOldValue,
42                                      (PVOID)pNewValue);
43     /*check the returned value*/
44     if(*(int *)pReturnValue != i1)
45     {
46         Fail("\nFailed to call InterlockedExchangePointer API, "
47                 "return pointer does not point to the origional value\n");
48     }
49
50     /*check the exchanged value*/
51     if(*pOldValue != *pNewValue)
52     {
53         Fail("\nFailed to call InterlockedExchangePointer API, "
54                 "exchanged value is not right\n");
55     }
56
57
58
59     /*
60       Clean Up
61     */
62     PAL_Terminate();
63     return PASS;
64 }