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: InterlockedDecrement64() 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 | int __cdecl main(int argc, char *argv[]) |
23 | { |
24 | LONGLONG TheValue = 0; |
25 | LONGLONG TheReturn; |
26 | |
27 | /* |
28 | * Initialize the PAL and return FAILURE if this fails |
29 | */ |
30 | |
31 | if(0 != (PAL_Initialize(argc, argv))) |
32 | { |
33 | return FAIL; |
34 | } |
35 | |
36 | /* |
37 | ** Run only on 64 bit platforms |
38 | */ |
39 | #if defined(BIT64) |
40 | /* Compare START_VALUE with BaseVariableToManipulate, they're equal, |
41 | so exchange |
42 | */ |
43 | InterlockedDecrement64(&TheValue); |
44 | TheReturn = InterlockedDecrement64(&TheValue); |
45 | |
46 | /* Decremented twice, it should be -2 now */ |
47 | if(TheValue != -2) |
48 | { |
49 | Fail("ERROR: After being decremented twice, the value should be -2, " |
50 | "but it is really %ll." ,TheValue); |
51 | } |
52 | |
53 | /* Check to make sure it returns itself */ |
54 | if(TheReturn != TheValue) |
55 | { |
56 | Fail("ERROR: The function should have returned the new value of %d " |
57 | "but instead returned %ll." ,TheValue,TheReturn); |
58 | } |
59 | #endif //defined(BIT64) |
60 | PAL_Terminate(); |
61 | return PASS; |
62 | } |
63 | |
64 | |
65 | |
66 | |
67 | |
68 | |