2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS system libraries
4 * FILE: lib/ntdll/rtl/intrlck.c
5 * PURPOSE: Inter lock increments
11 * Win32 kernel functions
13 * Copyright 1995 Martin von Loewis
14 * Copyright 1997 Onno Hovers
15 * Copied from kernel32
19 /************************************************************************
20 * InterlockedIncrement *
22 * InterlockedIncrement adds 1 to a long variable and returns *
23 * - a negative number if the result < 0 *
24 * - zero if the result == 0 *
25 * - a positive number if the result > 0 *
27 * The returned number need not be equal to the result!!!! *
30 ************************************************************************/
36 InterlockedIncrement(PLONG Addend)
41 "\tlock\n" /* for SMP systems */
49 :"=r" (ret):"r" (Addend), "0" (0): "memory"
54 /************************************************************************
55 * InterlockedDecrement *
57 * InterlockedIncrement adds 1 to a long variable and returns *
58 * - a negative number if the result < 0 *
59 * - zero if the result == 0 *
60 * - a positive number if the result > 0 *
62 * The returned number need not be equal to the result!!!! *
63 ************************************************************************/
67 InterlockedDecrement(LPLONG lpAddend)
72 "\tlock\n" /* for SMP systems */
80 :"=r" (ret):"r" (lpAddend), "0" (0): "memory"
87 /************************************************************************
90 * Atomically exchanges a pair of values.
93 * Prior value of value pointed to by Target
98 InterlockedExchange(LPLONG target, LONG value )
102 __asm__ ( /* lock for SMP systems */
103 "lock\n\txchgl %0,(%1)"
104 :"=r" (ret):"r" (target), "0" (value):"memory" );
110 /************************************************************************
111 * InterlockedCompareExchange
113 * Atomically compares Destination and Comperand, and if found equal exchanges
114 * the value of Destination with Exchange
117 * Prior value of value pointed to by Destination
121 InterlockedCompareExchange(
127 __asm__ ( /* lock for SMP systems */
131 :"r" (Destination),"r" (Exchange), "0" (Comperand)
137 /************************************************************************
138 * InterlockedExchangeAdd
140 * Atomically adds Increment to Addend and returns the previous value of
144 * Prior value of value pointed to by Addend
148 InterlockedExchangeAdd(
155 __asm__ ( /* lock for SMP systems */
159 :"r" (Addend), "0" (Increment)