85a6c4b4c586413d11560685a74f2139f1464a8b
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS system libraries
4 * FILE: lib/kernel32/sync/intrlck.c
5 * PURPOSE: Inter lock increments
11 * Win32 kernel functions
13 * Copyright 1995 Martin von Loewis
14 * Copyright 1997 Onno Hovers
18 /************************************************************************
19 * InterlockedIncrement *
21 * InterlockedIncrement adds 1 to a long variable and returns *
22 * - a negative number if the result < 0 *
23 * - zero if the result == 0 *
24 * - a positive number if the result > 0 *
26 * The returned number need not be equal to the result!!!! *
29 ************************************************************************/
35 InterlockedIncrement(PLONG Addend
)
40 "\tlock\n" /* for SMP systems */
48 :"=r" (ret
):"r" (Addend
), "0" (0): "memory"
53 /************************************************************************
54 * InterlockedDecrement *
56 * InterlockedIncrement adds 1 to a long variable and returns *
57 * - a negative number if the result < 0 *
58 * - zero if the result == 0 *
59 * - a positive number if the result > 0 *
61 * The returned number need not be equal to the result!!!! *
62 ************************************************************************/
66 InterlockedDecrement(LPLONG lpAddend
)
71 "\tlock\n" /* for SMP systems */
79 :"=r" (ret
):"r" (lpAddend
), "0" (0): "memory"
86 /************************************************************************
89 * Atomically exchanges a pair of values.
92 * Prior value of value pointed to by Target
97 InterlockedExchange(LPLONG target
, LONG value
)
101 __asm__ ( /* lock for SMP systems */
102 "lock\n\txchgl %0,(%1)"
103 :"=r" (ret
):"r" (target
), "0" (value
):"memory" );
109 /************************************************************************
110 * InterlockedCompareExchange
112 * Atomically compares Destination and Comperand, and if found equal exchanges
113 * the value of Destination with Exchange
116 * Prior value of value pointed to by Destination
120 InterlockedCompareExchange(
126 __asm__ ( /* lock for SMP systems */
130 :"r" (Destination
),"r" (Exchange
), "0" (Comperand
)
136 /************************************************************************
137 * InterlockedExchangeAdd
139 * Atomically adds Increment to Addend and returns the previous value of
143 * Prior value of value pointed to by Addend
147 InterlockedExchangeAdd(
154 __asm__ ( /* lock for SMP systems */
158 :"r" (Addend
), "0" (Increment
)