Author: hpoussin Date: Sun Jun 11 16:27:27 2006 New Revision: 22308
URL: http://svn.reactos.ru/svn/reactos?rev=22308&view=rev Log: Move Interlocked* functions to architecture-relative directories. This prevents use of inlined assembler.
Added: trunk/reactos/lib/intrlck/decrement.c (with props) trunk/reactos/lib/intrlck/exchange.c (with props) trunk/reactos/lib/intrlck/exchangeadd.c (with props) trunk/reactos/lib/intrlck/i386/ trunk/reactos/lib/intrlck/i386/compareexchange.s (with props) trunk/reactos/lib/intrlck/i386/decrement.s (with props) trunk/reactos/lib/intrlck/i386/exchange.s (with props) trunk/reactos/lib/intrlck/i386/exchangeadd.s (with props) trunk/reactos/lib/intrlck/i386/increment.s (with props) trunk/reactos/lib/intrlck/increment.c (with props) trunk/reactos/lib/intrlck/ppc/ trunk/reactos/lib/intrlck/ppc/compareexchange.c (with props) Removed: trunk/reactos/lib/intrlck/intrlck.c Modified: trunk/reactos/lib/intrlck/intrlck.rbuild
Added: trunk/reactos/lib/intrlck/decrement.c URL: http://svn.reactos.ru/svn/reactos/trunk/reactos/lib/intrlck/decrement.c?rev=... ============================================================================== --- trunk/reactos/lib/intrlck/decrement.c (added) +++ trunk/reactos/lib/intrlck/decrement.c Sun Jun 11 16:27:27 2006 @@ -1,0 +1,30 @@ +/* + * PROJECT: ReactOS system libraries + * LICENSE: GPL - See COPYING in the top level directory + * FILE: lib/intrlck/decrement.c + * PURPOSE: Inter lock decrements + * PROGRAMMERS: Copyright 1995 Martin von Loewis + * Copyright 1997 Onno Hovers + */ + +#include <windows.h> + +/************************************************************************ +* InterlockedDecrement * +* * +* InterlockedDecrement adds -1 to a long variable and returns * +* the resulting decremented value. * +* * +************************************************************************/ + +LONG NTAPI +InterlockedDecrement( + LPLONG lpAddend) +{ + LONG ret; + + ret = *lpAddend; + ret = InterlockedExchangeAdd( lpAddend, ret - 1 ); + + return ret; +}
Propchange: trunk/reactos/lib/intrlck/decrement.c ------------------------------------------------------------------------------ svn:eol-style = native
Added: trunk/reactos/lib/intrlck/exchange.c URL: http://svn.reactos.ru/svn/reactos/trunk/reactos/lib/intrlck/exchange.c?rev=2... ============================================================================== --- trunk/reactos/lib/intrlck/exchange.c (added) +++ trunk/reactos/lib/intrlck/exchange.c Sun Jun 11 16:27:27 2006 @@ -1,0 +1,34 @@ +/* + * PROJECT: ReactOS system libraries + * LICENSE: GPL - See COPYING in the top level directory + * FILE: lib/intrlck/exchange.c + * PURPOSE: Inter lock exchanges + * PROGRAMMERS: Copyright 1995 Martin von Loewis + * Copyright 1997 Onno Hovers + */ + +#include <windows.h> + +/************************************************************************ + * InterlockedExchange + * + * Atomically exchanges a pair of values. + * + * RETURNS + * Prior value of value pointed to by Target + */ + +LONG NTAPI +InterlockedExchange( + LPLONG target, + LONG value) +{ + LONG ret; + + do + { + ret = *(volatile LONG *)target; + } while( InterlockedCompareExchange( target, value, ret ) != ret ); + + return ret; +}
Propchange: trunk/reactos/lib/intrlck/exchange.c ------------------------------------------------------------------------------ svn:eol-style = native
Added: trunk/reactos/lib/intrlck/exchangeadd.c URL: http://svn.reactos.ru/svn/reactos/trunk/reactos/lib/intrlck/exchangeadd.c?re... ============================================================================== --- trunk/reactos/lib/intrlck/exchangeadd.c (added) +++ trunk/reactos/lib/intrlck/exchangeadd.c Sun Jun 11 16:27:27 2006 @@ -1,0 +1,37 @@ +/* + * PROJECT: ReactOS system libraries + * LICENSE: GPL - See COPYING in the top level directory + * FILE: lib/intrlck/exchangeadd.c + * PURPOSE: Inter lock exchange adds + * PROGRAMMERS: Copyright 1995 Martin von Loewis + * Copyright 1997 Onno Hovers + */ + +#include <windows.h> + +/************************************************************************ + * InterlockedExchangeAdd + * + * Atomically adds Increment to Addend and returns the previous value of + * Addend + * + * RETURNS + * Prior value of value pointed to by Addend + */ + +LONG NTAPI +InterlockedExchangeAdd( + PLONG Addend, + LONG Increment) +{ + LONG ret; + LONG newval; + + do + { + ret = *(volatile LONG *)Addend; + newval = ret + Increment; + } while (InterlockedCompareExchange(Addend, ret, newval) != ret); + + return ret; +}
Propchange: trunk/reactos/lib/intrlck/exchangeadd.c ------------------------------------------------------------------------------ svn:eol-style = native
Added: trunk/reactos/lib/intrlck/i386/compareexchange.s URL: http://svn.reactos.ru/svn/reactos/trunk/reactos/lib/intrlck/i386/compareexch... ============================================================================== --- trunk/reactos/lib/intrlck/i386/compareexchange.s (added) +++ trunk/reactos/lib/intrlck/i386/compareexchange.s Sun Jun 11 16:27:27 2006 @@ -1,0 +1,33 @@ +/* + * PROJECT: ReactOS system libraries + * LICENSE: GPL - See COPYING in the top level directory + * FILE: lib/intrlck/i386/compareexchange.s + * PURPOSE: Inter lock compare exchanges + * PROGRAMMERS: Copyright 1995 Martin von Loewis + * Copyright 1997 Onno Hovers + */ + +/************************************************************************ + * 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 + */ + +/* + * LONG NTAPI InterlockedCompareExchange(LPLONG Destination, LONG Exchange, LONG Comperand) + */ + +.globl _InterlockedCompareExchange@12 + +_InterlockedCompareExchange@12: + movl 12(%esp),%eax + movl 8(%esp),%ecx + movl 4(%esp),%edx + lock + cmpxchgl %ecx,(%edx) + leave + ret $12
Propchange: trunk/reactos/lib/intrlck/i386/compareexchange.s ------------------------------------------------------------------------------ svn:eol-style = native
Added: trunk/reactos/lib/intrlck/i386/decrement.s URL: http://svn.reactos.ru/svn/reactos/trunk/reactos/lib/intrlck/i386/decrement.s... ============================================================================== --- trunk/reactos/lib/intrlck/i386/decrement.s (added) +++ trunk/reactos/lib/intrlck/i386/decrement.s Sun Jun 11 16:27:27 2006 @@ -1,0 +1,31 @@ +/* + * PROJECT: ReactOS system libraries + * LICENSE: GPL - See COPYING in the top level directory + * FILE: lib/intrlck/i386/decrement.s + * PURPOSE: Inter lock decrements + * PROGRAMMERS: Copyright 1995 Martin von Loewis + * Copyright 1997 Onno Hovers + */ + +/************************************************************************ +* InterlockedDecrement * +* * +* InterlockedDecrement adds -1 to a long variable and returns * +* the resulting decremented value. * +* * +************************************************************************/ + +/* + * LONG NTAPI InterlockedDecrement(LPLONG lpAddend) + */ + +.globl _InterlockedDecrement@4 + +_InterlockedDecrement@4: + movl $-1,%ebx + lock + xaddl %eax,%ebx + decl %eax + leave + ret $4 +
Propchange: trunk/reactos/lib/intrlck/i386/decrement.s ------------------------------------------------------------------------------ svn:eol-style = native
Added: trunk/reactos/lib/intrlck/i386/exchange.s URL: http://svn.reactos.ru/svn/reactos/trunk/reactos/lib/intrlck/i386/exchange.s?... ============================================================================== --- trunk/reactos/lib/intrlck/i386/exchange.s (added) +++ trunk/reactos/lib/intrlck/i386/exchange.s Sun Jun 11 16:27:27 2006 @@ -1,0 +1,29 @@ +/* + * PROJECT: ReactOS system libraries + * LICENSE: GPL - See COPYING in the top level directory + * FILE: lib/intrlck/i386/exchange.s + * PURPOSE: Inter lock exchanges + * PROGRAMMERS: Copyright 1995 Martin von Loewis + * Copyright 1997 Onno Hovers + */ + +/************************************************************************ + * InterlockedExchange + * + * Atomically exchanges a pair of values. + * + * RETURNS + * Prior value of value pointed to by Target + */ + +/* + * LONG NTAPI InterlockedExchange(LPLONG target, LONG value) + */ + +.globl _InterlockedExchange@8 + +_InterlockedExchange@8: + lock + xchgl %eax,%ebx + leave + ret $8
Propchange: trunk/reactos/lib/intrlck/i386/exchange.s ------------------------------------------------------------------------------ svn:eol-style = native
Added: trunk/reactos/lib/intrlck/i386/exchangeadd.s URL: http://svn.reactos.ru/svn/reactos/trunk/reactos/lib/intrlck/i386/exchangeadd... ============================================================================== --- trunk/reactos/lib/intrlck/i386/exchangeadd.s (added) +++ trunk/reactos/lib/intrlck/i386/exchangeadd.s Sun Jun 11 16:27:27 2006 @@ -1,0 +1,30 @@ +/* + * PROJECT: ReactOS system libraries + * LICENSE: GPL - See COPYING in the top level directory + * FILE: lib/intrlck/i386/exchangeadd.s + * PURPOSE: Inter lock exchange adds + * PROGRAMMERS: Copyright 1995 Martin von Loewis + * Copyright 1997 Onno Hovers + */ + +/************************************************************************ + * InterlockedExchangeAdd + * + * Atomically adds Increment to Addend and returns the previous value of + * Addend + * + * RETURNS + * Prior value of value pointed to by Addend + */ + +/* + * LONG NTAPI InterlockedExchangeAdd(PLONG Addend, LONG Increment) + */ + +.globl _InterlockedExchangeAdd@8 + +_InterlockedExchangeAdd@8: + lock + xaddl %eax,%ebx + leave + ret $4
Propchange: trunk/reactos/lib/intrlck/i386/exchangeadd.s ------------------------------------------------------------------------------ svn:eol-style = native
Added: trunk/reactos/lib/intrlck/i386/increment.s URL: http://svn.reactos.ru/svn/reactos/trunk/reactos/lib/intrlck/i386/increment.s... ============================================================================== --- trunk/reactos/lib/intrlck/i386/increment.s (added) +++ trunk/reactos/lib/intrlck/i386/increment.s Sun Jun 11 16:27:27 2006 @@ -1,0 +1,30 @@ +/* + * PROJECT: ReactOS system libraries + * LICENSE: GPL - See COPYING in the top level directory + * FILE: lib/intrlck/i386/increment.s + * PURPOSE: Inter lock increments + * PROGRAMMERS: Copyright 1995 Martin von Loewis + * Copyright 1997 Onno Hovers + */ + +/************************************************************************ +* InterlockedIncrement * +* * +* InterlockedIncrement adds 1 to a long variable and returns * +* the resulting incremented value. * +* * +************************************************************************/ + +/* + * LONG NTAPI InterlockedIncrement(PLONG Addend) + */ + +.globl _InterlockedIncrement@4 + +_InterlockedIncrement@4: + movl $1,%ebx + lock + xaddl %eax,%ebx + incl %eax + leave + ret $4
Propchange: trunk/reactos/lib/intrlck/i386/increment.s ------------------------------------------------------------------------------ svn:eol-style = native
Added: trunk/reactos/lib/intrlck/increment.c URL: http://svn.reactos.ru/svn/reactos/trunk/reactos/lib/intrlck/increment.c?rev=... ============================================================================== --- trunk/reactos/lib/intrlck/increment.c (added) +++ trunk/reactos/lib/intrlck/increment.c Sun Jun 11 16:27:27 2006 @@ -1,0 +1,30 @@ +/* + * PROJECT: ReactOS system libraries + * LICENSE: GPL - See COPYING in the top level directory + * FILE: lib/intrlck/increment.c + * PURPOSE: Inter lock increments + * PROGRAMMERS: Copyright 1995 Martin von Loewis + * Copyright 1997 Onno Hovers + */ + +#include <windows.h> + +/************************************************************************ +* InterlockedIncrement * +* * +* InterlockedIncrement adds 1 to a long variable and returns * +* the resulting incremented value. * +* * +************************************************************************/ + +LONG NTAPI +InterlockedIncrement( + PLONG Addend) +{ + LONG ret; + + ret = *Addend; + ret = InterlockedExchangeAdd( Addend, ret + 1 ); + + return ret; +}
Propchange: trunk/reactos/lib/intrlck/increment.c ------------------------------------------------------------------------------ svn:eol-style = native
Removed: trunk/reactos/lib/intrlck/intrlck.c URL: http://svn.reactos.ru/svn/reactos/trunk/reactos/lib/intrlck/intrlck.c?rev=22... ============================================================================== --- trunk/reactos/lib/intrlck/intrlck.c (original) +++ trunk/reactos/lib/intrlck/intrlck.c (removed) @@ -1,209 +1,0 @@ -/* - * 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 - */ - -/* PowerPC Functions from gatomic.c in glib - * - * GLIB - Library of useful routines for C programming - * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald - * - * g_atomic_*: atomic operations. - * Copyright (C) 2003 Sebastian Wilhelmi - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -/************************************************************************ -* InterlockedIncrement * -* * -* InterlockedIncrement adds 1 to a long variable and returns * -* the resulting incremented value. * -* * -************************************************************************/ - -#include <windows.h> - -LONG -STDCALL -InterlockedIncrement(PLONG Addend) -{ - long ret; -#ifdef _M_IX86 - __asm__ - ( - "\tlock\n" /* for SMP systems */ - "\txaddl %0, (%1)\n" - "\tincl %0\n" - :"=r" (ret) - :"r" (Addend), "0" (1) - : "memory" - ); -#elif defined(_M_PPC) - ret = *Addend; - ret = InterlockedExchangeAdd( Addend, ret + 1 ); -#else -#error Unknown compiler for inline assembler -#endif - return ret; -} - -/************************************************************************ -* InterlockedDecrement * -* * -* InterlockedDecrement adds -1 to a long variable and returns * -* the resulting decremented value. * -* * -************************************************************************/ - -LONG -STDCALL -InterlockedDecrement(LPLONG lpAddend) -{ - long ret; -#ifdef _M_IX86 - __asm__ - ( - "\tlock\n" /* for SMP systems */ - "\txaddl %0, (%1)\n" - "\tdecl %0\n" - :"=r" (ret) - :"r" (lpAddend), "0" (-1) - : "memory" - ); -#elif defined(_M_PPC) - ret = *lpAddend; - ret = InterlockedExchangeAdd( lpAddend, ret - 1 ); -#else -#error Unknown compiler for inline assembler -#endif - 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; -#ifdef _M_IX86 - __asm__ ( /* lock for SMP systems */ - "lock\n\txchgl %0,(%1)" - :"=r" (ret):"r" (target), "0" (value):"memory" ); -#elif defined(_M_PPC) - do { - ret = *(volatile LONG *)target; - } while( InterlockedCompareExchange( target, value, ret ) != ret ); -#else -#error Unknown compiler for inline assembler -#endif - 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 - */ -LONG -STDCALL -InterlockedCompareExchange( - LPLONG Destination, - LONG Exchange, - LONG Comperand ) -{ - LONG ret; -#ifdef _M_IX86 - __asm__ __volatile__( "lock; cmpxchgl %2,(%1)" - : "=a" (ret) : "r" (Destination), "r" (Exchange), "0" (Comperand) : "memory" ); -#elif defined(_M_PPC) - __asm__ __volatile__ ("sync\n" - "1: lwarx %0,0,%1\n" - " subf. %0,%2,%0\n" - " bne 2f\n" - " stwcx. %3,0,%1\n" - " bne- 1b\n" - "2: isync" - : "=&r" (ret) - : "b" (Destination), "r" (Comperand), "r" (Exchange) - : "cr0", "memory"); -#else -#error Unknown compiler for inline assembler -#endif - 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; -#ifdef _M_IX86 - __asm__ ( /* lock for SMP systems */ - "lock\n\t" - "xaddl %0,(%1)" - :"=r" (ret) - :"r" (Addend), "0" (Increment) - :"memory" ); -#elif defined(_M_PPC) - LONG newval; - do { - ret = *(volatile LONG *)Addend; - newval = ret + Increment; - } while (InterlockedCompareExchange(Addend, ret, newval) != ret); -#else -#error Unknown compiler for inline assembler -#endif - return ret; -}
Modified: trunk/reactos/lib/intrlck/intrlck.rbuild URL: http://svn.reactos.ru/svn/reactos/trunk/reactos/lib/intrlck/intrlck.rbuild?r... ============================================================================== --- trunk/reactos/lib/intrlck/intrlck.rbuild (original) +++ trunk/reactos/lib/intrlck/intrlck.rbuild Sun Jun 11 16:27:27 2006 @@ -1,4 +1,22 @@ <module name="intrlck" type="staticlibrary"> <define name="__USE_W32API" /> - <file>intrlck.c</file> + + <if property="ARCH" value="i386"> + <directory name="i386"> + <file>compareexchange.s</file> + <file>decrement.s</file> + <file>exchange.s</file> + <file>exchangeadd.s</file> + <file>increment.s</file> + </directory> + </if> + <if property="ARCH" value="ppc"> + <directory name="ppc"> + <file>compareexchange.c</file> + </directory> + <file>decrement.c</file> + <file>exchange.c</file> + <file>exchangeadd.c</file> + <file>increment.c</file> + </if> </module>
Added: trunk/reactos/lib/intrlck/ppc/compareexchange.c URL: http://svn.reactos.ru/svn/reactos/trunk/reactos/lib/intrlck/ppc/compareexcha... ============================================================================== --- trunk/reactos/lib/intrlck/ppc/compareexchange.c (added) +++ trunk/reactos/lib/intrlck/ppc/compareexchange.c Sun Jun 11 16:27:27 2006 @@ -1,0 +1,60 @@ +/* PowerPC Functions from gatomic.c in glib + * + * GLIB - Library of useful routines for C programming + * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald + * + * g_atomic_*: atomic operations. + * Copyright (C) 2003 Sebastian Wilhelmi + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +/************************************************************************ + * 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 + */ + +/* + * LONG NTAPI InterlockedCompareExchange(LPLONG Destination, LONG Exchange, LONG Comperand) + */ + +#include <windows.h> +LONG +NTAPI +InterlockedCompareExchange( + LPLONG Destination, + long Exchange, + LONG Comperand) +{ + LONG ret; + __asm__ __volatile__ ( + "sync\n" + "1: lwarx %0,0,%1\n" + " subf. %0,%2,%0\n" + " bne 2f\n" + " stwcx. %3,0,%1\n" + " bne- 1b\n" + "2: isync" + : "=&r" (ret) + : "b" (Destination), "r" (Comperand), "r" (Exchange) + : "cr0", "memory"); + return ret; +}
Propchange: trunk/reactos/lib/intrlck/ppc/compareexchange.c ------------------------------------------------------------------------------ svn:eol-style = native