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.
5 /*============================================================
9 ** Purpose: InterlockedExchange64() function
12 **=========================================================*/
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?
24 int __cdecl main(int argc, char *argv[]) {
26 LONGLONG TheValue = START_VALUE;
27 LONGLONG NewValue = 5;
31 * Initialize the PAL and return FAILURE if this fails
34 if(0 != (PAL_Initialize(argc, argv)))
40 ** Run only on 64 bit platforms
42 #if defined(BIT64) && defined(PLATFORM_UNIX)
44 TheReturn = InterlockedExchange64(&TheValue,NewValue);
46 /* Compare the exchanged value with the value we exchanged it with. Should
49 if(TheValue != NewValue)
52 Fail("ERROR: The value which was exchanged should now be %ll, but "
53 "instead it is %ll.",NewValue,TheValue);
55 Fail("ERROR: The value which was exchanged should now be %I64, but "
56 "instead it is %I64.",NewValue,TheValue);
60 /* Check to make sure it returns the origional number which 'TheValue' was
64 if(TheReturn != START_VALUE)
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);
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);
77 #endif // BIT64 && PLATFORM_UNIX