test: intrloc2.c Source File

Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

# intrloc2.c

Go to the documentation of this file.

    00001 /*++
    00002
    00003 Copyright (c) 1989  Microsoft Corporation
    00004
    00005 Module Name:
    00006
    00007     intrloc2.c
    00008
    00009 Abstract:
    00010
    00011    This module implements the *portable*  (i.e. SLOW) versions of
    00012    the executive's simple atomic increment/decrement procedures.
    00013    Real implementation should be in assembler.
    00014
    00015 Author:
    00016
    00017     Bryan Willman  (bryanwi)  2-Aug-90
    00018
    00019 Environment:
    00020
    00021     Kernel mode only.
    00022
    00023 Revision History:
    00024
    00025 --*/
    00026
    00027 #include "exp.h"
    00028
    00029 INTERLOCKED_RESULT
    00030 ExInterlockedIncrementLong (
    00031     IN PLONG Addend,
    00032     IN PKSPIN_LOCK Lock
    00033     )
    00034
    00035 /*++
    00036
    00037 Routine Description:
    00038
    00039     This function atomically increments Addend, returning an ennumerated
    00040     type which indicates what interesting transitions in the value of
    00041     Addend occurred due the operation.
    00042
    00043 Arguments:
    00044
    00045     Addend - Pointer to variable to increment.
    00046
    00047     Lock - Spinlock used to implement atomicity.
    00048
    00049 Return Value:
    00050
    00051     An ennumerated type:
    00052
    00053     ResultNegative if Addend is < 0 after increment.
    00054     ResultZero     if Addend is = 0 after increment.
    00055     ResultPositive if Addend is > 0 after increment.
    00056
    00057 --*/
    00058
    00059 {
    00060     LONG    OldValue;
    00061
    00062     OldValue = (LONG)ExInterlockedAddUlong((PULONG)Addend, 1, Lock);
    00063
    00064     if (OldValue < -1)
    00065         return ResultNegative;
    00066
    00067     if (OldValue == -1)
    00068         return ResultZero;
    00069
    00070     if (OldValue > -1)
    00071         return ResultPositive;
    00072 }
    00073
    00074 INTERLOCKED_RESULT
    00075 ExInterlockedDecrementLong (
    00076     IN PLONG Addend,
    00077     IN PKSPIN_LOCK Lock
    00078     )
    00079
    00080 /*++
    00081
    00082 Routine Description:
    00083
    00084     This function atomically decrements Addend, returning an ennumerated
    00085     type which indicates what interesting transitions in the value of
    00086     Addend occurred due the operation.
    00087
    00088 Arguments:
    00089
    00090     Addend - Pointer to variable to decrement.
    00091
    00092     Lock - Spinlock used to implement atomicity.
    00093
    00094 Return Value:
    00095
    00096     An ennumerated type:
    00097
    00098     ResultNegative if Addend is < 0 after decrement.
    00099     ResultZero     if Addend is = 0 after decrement.
    00100     ResultPositive if Addend is > 0 after decrement.
    00101
    00102 --*/
    00103
    00104 {
    00105     LONG    OldValue;
    00106
    00107     OldValue = (LONG)ExInterlockedAddUlong((PULONG)Addend, -1, Lock);
    00108
    00109     if (OldValue > 1)
    00110         return ResultPositive;
    00111
    00112     if (OldValue == 1)
    00113         return ResultZero;
    00114
    00115     if (OldValue < 1)
    00116         return ResultNegative;
    00117 }