Remove obsolete platforms ifdefs from PAL (#8971)
[platform/upstream/coreclr.git] / src / pal / tests / palsuite / miscellaneous / InterlockedExchange64 / test1 / test.cpp
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: test.c
8 **
9 ** Purpose: InterlockedExchange64() function
10 **
11 **
12 **=========================================================*/
13
14 /* This test is FINISHED.  Note:  The biggest feature of this function is that
15    it locks the value before it increments it -- in order to make it so only 
16    one thread can access it.  But, I really don't have a great test to make 
17    sure it's thread safe.  Any ideas?
18 */
19
20 #include <palsuite.h>
21
22 #define START_VALUE 0
23
24 int __cdecl main(int argc, char *argv[]) {
25
26     LONGLONG TheValue = START_VALUE;
27     LONGLONG NewValue = 5;
28     LONGLONG TheReturn;
29
30     /*
31      * Initialize the PAL and return FAILURE if this fails
32      */
33
34     if(0 != (PAL_Initialize(argc, argv)))
35     {
36         return FAIL;
37     }
38
39 /*
40 **  Run only on 64 bit platforms
41 */
42 #if defined(BIT64) && defined(PLATFORM_UNIX)
43
44     TheReturn = InterlockedExchange64(&TheValue,NewValue);
45   
46     /* Compare the exchanged value with the value we exchanged it with.  Should
47        be the same.
48     */  
49     if(TheValue != NewValue) 
50     {
51 #ifdef PLATFORM_UNIX
52         Fail("ERROR: The value which was exchanged should now be %ll, but "
53              "instead it is %ll.",NewValue,TheValue);    
54 #else
55         Fail("ERROR: The value which was exchanged should now be %I64, but "
56              "instead it is %I64.",NewValue,TheValue);    
57 #endif
58     }
59   
60     /* Check to make sure it returns the origional number which 'TheValue' was 
61        set to. 
62     */
63   
64     if(TheReturn != START_VALUE) 
65     {
66 #ifdef PLATFORM_UNIX
67         Fail("ERROR: The value returned should be the value before the "
68              "exchange happened, which was %ll, but %ll was returned.",
69              START_VALUE,TheReturn);
70 #else
71         Fail("ERROR: The value returned should be the value before the "
72              "exchange happened, which was %I64, but %I64 was returned.",
73              START_VALUE,TheReturn);
74 #endif
75     }
76
77 #endif  // BIT64 && PLATFORM_UNIX
78     PAL_Terminate();
79     return PASS; 
80
81
82
83
84
85