| 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: InterlockedIncrement64() 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? Nothing I've tried has worked. |
| 18 | */ |
| 19 | |
| 20 | |
| 21 | #include <palsuite.h> |
| 22 | |
| 23 | int __cdecl main(int argc, char *argv[]) |
| 24 | { |
| 25 | |
| 26 | LONGLONG TheValue = 0; |
| 27 | LONGLONG TheReturn; |
| 28 | |
| 29 | /* |
| 30 | * Initialize the PAL and return FAILURE if this fails |
| 31 | */ |
| 32 | |
| 33 | if(0 != (PAL_Initialize(argc, argv))) |
| 34 | { |
| 35 | return FAIL; |
| 36 | } |
| 37 | /* |
| 38 | ** Run only on 64 bit platforms |
| 39 | */ |
| 40 | #if defined(BIT64) |
| 41 | |
| 42 | InterlockedIncrement64(&TheValue); |
| 43 | TheReturn = InterlockedIncrement64(&TheValue); |
| 44 | |
| 45 | /* Incremented twice, it should be 2 now */ |
| 46 | if(TheValue != 2) |
| 47 | { |
| 48 | Fail("ERROR: The value was incremented twice and shoud now be 2, " |
| 49 | "but it is really %ll" ,TheValue); |
| 50 | } |
| 51 | |
| 52 | /* Check to make sure it returns itself */ |
| 53 | if(TheReturn != TheValue) |
| 54 | { |
| 55 | Fail("ERROR: The function should return the new value, which shoud " |
| 56 | "have been %d, but it returned %ll." ,TheValue,TheReturn); |
| 57 | } |
| 58 | |
| 59 | #endif //defined(BIT64) |
| 60 | PAL_Terminate(); |
| 61 | return PASS; |
| 62 | } |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |