move from branch
[reactos.git] / reactos / lib / intrlck / i386 / compareexchange.c
1 /*
2 * PROJECT: ReactOS system libraries
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: lib/intrlck/i386/compareexchange.c
5 * PURPOSE: Inter lock compare exchanges
6 * PROGRAMMERS: Copyright 1995 Martin von Loewis
7 * Copyright 1997 Onno Hovers
8 */
9
10 /************************************************************************
11 * InterlockedCompareExchange
12 *
13 * Atomically compares Destination and Comperand, and if found equal exchanges
14 * the value of Destination with Exchange
15 *
16 * RETURNS
17 * Prior value of value pointed to by Destination
18 */
19
20 /*
21 * LONG NTAPI InterlockedCompareExchange(LPLONG Destination, LONG Exchange, LONG Comperand)
22 */
23
24 #include <windows.h>
25 LONG
26 NTAPI
27 InterlockedCompareExchange(
28 IN OUT LONG volatile *Destination,
29 LONG Exchange,
30 LONG Comperand)
31 {
32 LONG ret;
33 __asm__ __volatile__(
34 "lock; cmpxchgl %2,(%1)"
35 : "=a" (ret) : "r" (Destination), "r" (Exchange), "0" (Comperand) : "memory" );
36 return ret;
37 }