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
24int __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)
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 Fail("ERROR: The value which was exchanged should now be %ll, but "
52 "instead it is %ll.",NewValue,TheValue);
53 }
54
55 /* Check to make sure it returns the origional number which 'TheValue' was
56 set to.
57 */
58
59 if(TheReturn != START_VALUE)
60 {
61 Fail("ERROR: The value returned should be the value before the "
62 "exchange happened, which was %ll, but %ll was returned.",
63 START_VALUE,TheReturn);
64 }
65
66#endif // BIT64
67 PAL_Terminate();
68 return PASS;
69}
70
71
72
73
74
75