diff --git a/reactos/lib/ntdll/def/ntdll.def b/reactos/lib/ntdll/def/ntdll.def index bfae0772dc0..ad33a5a38f7 100644 --- a/reactos/lib/ntdll/def/ntdll.def +++ b/reactos/lib/ntdll/def/ntdll.def @@ -1,4 +1,4 @@ -; $Id: ntdll.def,v 1.67 2000/12/29 13:49:15 ekohl Exp $ +; $Id: ntdll.def,v 1.68 2001/01/21 00:07:51 phreak Exp $ ; ; ReactOS Operating System ; @@ -933,4 +933,8 @@ wcsstr wcstol wcstombs wcstoul +InterlockedIncrement@4 +InterlockedDecrement@4 +InterlockedExchange@8 +InterlockedCompareExchange@12 ;EOF diff --git a/reactos/lib/ntdll/def/ntdll.edf b/reactos/lib/ntdll/def/ntdll.edf index fee46b0a118..48c80a90a9c 100644 --- a/reactos/lib/ntdll/def/ntdll.edf +++ b/reactos/lib/ntdll/def/ntdll.edf @@ -1,4 +1,4 @@ -; $Id: ntdll.edf,v 1.56 2000/12/29 13:49:15 ekohl Exp $ +; $Id: ntdll.edf,v 1.57 2001/01/21 00:07:51 phreak Exp $ ; ; ReactOS Operating System ; @@ -814,6 +814,10 @@ ZwWriteRequestData=ZwWriteRequestData@24 ZwWriteVirtualMemory=ZwWriteVirtualMemory@20 ZwW32Call=ZwW32Call@20 ZwYieldExecution=ZwYieldExecution@0 +InterlockedIncrement=InterlockedIncrement@4 +InterlockedDecrement=InterlockedDecrement@4 +InterlockedExchange=InterlockedExchange@8 +InterlockedCompareExchange=InterlockedCompareExchange@12 __isascii __iscsym __iscsymf diff --git a/reactos/lib/ntdll/makefile b/reactos/lib/ntdll/makefile index 714674085c2..953c8900344 100644 --- a/reactos/lib/ntdll/makefile +++ b/reactos/lib/ntdll/makefile @@ -1,4 +1,4 @@ -# $Id: makefile,v 1.57 2001/01/17 17:01:38 jean Exp $ +# $Id: makefile,v 1.58 2001/01/21 00:07:51 phreak Exp $ # # ReactOS Operating System # @@ -24,7 +24,7 @@ RTL_OBJECTS = rtl/critical.o rtl/error.o rtl/heap.o rtl/largeint.o \ rtl/thread.o rtl/unicode.o rtl/env.o rtl/path.o rtl/ppb.o \ rtl/bitmap.o rtl/time.o rtl/acl.o rtl/sid.o rtl/image.o \ rtl/access.o rtl/apc.o rtl/callback.o rtl/luid.o rtl/misc.o \ - rtl/registry.o rtl/exception.o + rtl/registry.o rtl/exception.o rtl/intrlck.o STDIO_OBJECTS = stdio/sprintf.o stdio/swprintf.o diff --git a/reactos/lib/ntdll/rtl/critical.c b/reactos/lib/ntdll/rtl/critical.c index 53a7c3790ca..bd18e435117 100644 --- a/reactos/lib/ntdll/rtl/critical.c +++ b/reactos/lib/ntdll/rtl/critical.c @@ -1,4 +1,4 @@ -/* $Id: critical.c,v 1.8 2000/08/05 18:01:52 dwelch Exp $ +/* $Id: critical.c,v 1.9 2001/01/21 00:07:51 phreak Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS system libraries @@ -17,65 +17,6 @@ /* FUNCTIONS *****************************************************************/ -/* shouldn't these have correct Rtl equivalents? I just copied from kernel32 */ - -PVOID STDCALL -InterlockedCompareExchange( - PVOID *Destination, - PVOID Exchange, - PVOID Comperand ) -{ - PVOID ret; - __asm__ ( /* lock for SMP systems */ - "lock\n\t" - "cmpxchgl %2,(%1)" - :"=r" (ret) - :"r" (Destination),"r" (Exchange), "0" (Comperand) - :"memory" ); - return ret; - -} - -LONG STDCALL -InterlockedIncrement(PLONG Addend) -{ - long ret = 0; - __asm__ - ( - "\tlock\n" /* for SMP systems */ - "\tincl (%1)\n" - "\tje 2f\n" - "\tjl 1f\n" - "\tincl %0\n" - "\tjmp 2f\n" - "1:\tdec %0\n" - "2:\n" - :"=r" (ret):"r" (Addend), "0" (0): "memory" - ); - return ret; -} - -LONG STDCALL -InterlockedDecrement(PLONG lpAddend) -{ - long ret; - __asm__ - ( - "\tlock\n" /* for SMP systems */ - "\tdecl (%1)\n" - "\tje 2f\n" - "\tjl 1f\n" - "\tincl %0\n" - "\tjmp 2f\n" - "1:\tdec %0\n" - "2:\n" - :"=r" (ret):"r" (lpAddend), "0" (0): "memory" - ); - return ret; - - -} - VOID STDCALL RtlDeleteCriticalSection(LPCRITICAL_SECTION lpCriticalSection) { diff --git a/reactos/lib/ntdll/rtl/intrlck.c b/reactos/lib/ntdll/rtl/intrlck.c new file mode 100644 index 00000000000..5e91816b2a7 --- /dev/null +++ b/reactos/lib/ntdll/rtl/intrlck.c @@ -0,0 +1,163 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * FILE: lib/ntdll/rtl/intrlck.c + * PURPOSE: Inter lock increments + * UPDATE HISTORY: + * Created 30/09/99 + */ + +/* + * Win32 kernel functions + * + * Copyright 1995 Martin von Loewis + * Copyright 1997 Onno Hovers + * Copied from kernel32 + */ + + +/************************************************************************ +* InterlockedIncrement * +* * +* InterlockedIncrement adds 1 to a long variable and returns * +* - a negative number if the result < 0 * +* - zero if the result == 0 * +* - a positive number if the result > 0 * +* * +* The returned number need not be equal to the result!!!! * +* note: * +* * +************************************************************************/ + +#include + +LONG +STDCALL +InterlockedIncrement(PLONG Addend) +{ + long ret = 0; + __asm__ + ( + "\tlock\n" /* for SMP systems */ + "\tincl (%1)\n" + "\tje 2f\n" + "\tjl 1f\n" + "\tincl %0\n" + "\tjmp 2f\n" + "1:\tdec %0\n" + "2:\n" + :"=r" (ret):"r" (Addend), "0" (0): "memory" + ); + return ret; +} + +/************************************************************************ +* InterlockedDecrement * +* * +* InterlockedIncrement adds 1 to a long variable and returns * +* - a negative number if the result < 0 * +* - zero if the result == 0 * +* - a positive number if the result > 0 * +* * +* The returned number need not be equal to the result!!!! * +************************************************************************/ + +LONG +STDCALL +InterlockedDecrement(LPLONG lpAddend) +{ + long ret; + __asm__ + ( + "\tlock\n" /* for SMP systems */ + "\tdecl (%1)\n" + "\tje 2f\n" + "\tjl 1f\n" + "\tincl %0\n" + "\tjmp 2f\n" + "1:\tdec %0\n" + "2:\n" + :"=r" (ret):"r" (lpAddend), "0" (0): "memory" + ); + return ret; + + +} + +/************************************************************************ + * InterlockedExchange + * + * Atomically exchanges a pair of values. + * + * RETURNS + * Prior value of value pointed to by Target + */ + +LONG +STDCALL +InterlockedExchange(LPLONG target, LONG value ) +{ + + long ret; + __asm__ ( /* lock for SMP systems */ + "lock\n\txchgl %0,(%1)" + :"=r" (ret):"r" (target), "0" (value):"memory" ); + return ret; + + +} + +/************************************************************************ + * InterlockedCompareExchange + * + * Atomically compares Destination and Comperand, and if found equal exchanges + * the value of Destination with Exchange + * + * RETURNS + * Prior value of value pointed to by Destination + */ +PVOID +STDCALL +InterlockedCompareExchange( + PVOID *Destination, + PVOID Exchange, + PVOID Comperand ) +{ + PVOID ret; + __asm__ ( /* lock for SMP systems */ + "lock\n\t" + "cmpxchgl %2,(%1)" + :"=r" (ret) + :"r" (Destination),"r" (Exchange), "0" (Comperand) + :"memory" ); + return ret; + +} + +/************************************************************************ + * InterlockedExchangeAdd + * + * Atomically adds Increment to Addend and returns the previous value of + * Addend + * + * RETURNS + * Prior value of value pointed to by Addend + */ +LONG +STDCALL +InterlockedExchangeAdd( + PLONG Addend, + LONG Increment +) +{ + + LONG ret; + __asm__ ( /* lock for SMP systems */ + "lock\n\t" + "xaddl %0,(%1)" + :"=r" (ret) + :"r" (Addend), "0" (Increment) + :"memory" ); + return ret; + +}