| 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: InterlockedDecrement() 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 | int TheValue = 0; |
| 25 | int 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 | InterlockedDecrement(&TheValue); |
| 37 | TheReturn = InterlockedDecrement(&TheValue); |
| 38 | |
| 39 | /* Decremented twice, it should be -2 now */ |
| 40 | if(TheValue != -2) |
| 41 | { |
| 42 | Fail("ERROR: After being decremented twice, the value should be -2, " |
| 43 | "but it is really %d." ,TheValue); |
| 44 | } |
| 45 | |
| 46 | /* Check to make sure it returns itself */ |
| 47 | if(TheReturn != TheValue) |
| 48 | { |
| 49 | Fail("ERROR: The function should have returned the new value of %d " |
| 50 | "but instead returned %d." ,TheValue,TheReturn); |
| 51 | } |
| 52 | |
| 53 | PAL_Terminate(); |
| 54 | return PASS; |
| 55 | } |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | |