mirror of
https://github.com/reactos/reactos.git
synced 2025-08-04 01:15:42 +00:00
Move Interlocked* routines from ROSRTL to separate INTRLCK library since ROSRTL is going to be removed.
svn path=/trunk/; revision=16539
This commit is contained in:
parent
fcc95c66a8
commit
e36f90a9f9
7 changed files with 219 additions and 211 deletions
|
@ -91,6 +91,9 @@
|
||||||
<directory name="imm32">
|
<directory name="imm32">
|
||||||
<xi:include href="imm32/imm32.xml" />
|
<xi:include href="imm32/imm32.xml" />
|
||||||
</directory>
|
</directory>
|
||||||
|
<directory name="intrlck">
|
||||||
|
<xi:include href="intrlck/intrlck.xml" />
|
||||||
|
</directory>
|
||||||
<directory name="iphlpapi">
|
<directory name="iphlpapi">
|
||||||
<xi:include href="iphlpapi/iphlpapi.xml" />
|
<xi:include href="iphlpapi/iphlpapi.xml" />
|
||||||
</directory>
|
</directory>
|
||||||
|
|
|
@ -1,209 +1,209 @@
|
||||||
/*
|
/*
|
||||||
* COPYRIGHT: See COPYING in the top level directory
|
* COPYRIGHT: See COPYING in the top level directory
|
||||||
* PROJECT: ReactOS system libraries
|
* PROJECT: ReactOS system libraries
|
||||||
* FILE: lib/ntdll/rtl/intrlck.c
|
* FILE: lib/ntdll/rtl/intrlck.c
|
||||||
* PURPOSE: Inter lock increments
|
* PURPOSE: Inter lock increments
|
||||||
* UPDATE HISTORY:
|
* UPDATE HISTORY:
|
||||||
* Created 30/09/99
|
* Created 30/09/99
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Win32 kernel functions
|
* Win32 kernel functions
|
||||||
*
|
*
|
||||||
* Copyright 1995 Martin von Loewis
|
* Copyright 1995 Martin von Loewis
|
||||||
* Copyright 1997 Onno Hovers
|
* Copyright 1997 Onno Hovers
|
||||||
* Copied from kernel32
|
* Copied from kernel32
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* PowerPC Functions from gatomic.c in glib
|
/* PowerPC Functions from gatomic.c in glib
|
||||||
*
|
*
|
||||||
* GLIB - Library of useful routines for C programming
|
* GLIB - Library of useful routines for C programming
|
||||||
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
||||||
*
|
*
|
||||||
* g_atomic_*: atomic operations.
|
* g_atomic_*: atomic operations.
|
||||||
* Copyright (C) 2003 Sebastian Wilhelmi
|
* Copyright (C) 2003 Sebastian Wilhelmi
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
* License as published by the Free Software Foundation; either
|
* License as published by the Free Software Foundation; either
|
||||||
* version 2 of the License, or (at your option) any later version.
|
* version 2 of the License, or (at your option) any later version.
|
||||||
*
|
*
|
||||||
* This library is distributed in the hope that it will be useful,
|
* This library is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
* Lesser General Public License for more details.
|
* Lesser General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU Lesser General Public
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
* License along with this library; if not, write to the
|
* License along with this library; if not, write to the
|
||||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||||
* Boston, MA 02111-1307, USA.
|
* Boston, MA 02111-1307, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* InterlockedIncrement *
|
* InterlockedIncrement *
|
||||||
* *
|
* *
|
||||||
* InterlockedIncrement adds 1 to a long variable and returns *
|
* InterlockedIncrement adds 1 to a long variable and returns *
|
||||||
* the resulting incremented value. *
|
* the resulting incremented value. *
|
||||||
* *
|
* *
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
LONG
|
LONG
|
||||||
STDCALL
|
STDCALL
|
||||||
InterlockedIncrement(PLONG Addend)
|
InterlockedIncrement(PLONG Addend)
|
||||||
{
|
{
|
||||||
long ret;
|
long ret;
|
||||||
#ifdef _M_IX86
|
#ifdef _M_IX86
|
||||||
__asm__
|
__asm__
|
||||||
(
|
(
|
||||||
"\tlock\n" /* for SMP systems */
|
"\tlock\n" /* for SMP systems */
|
||||||
"\txaddl %0, (%1)\n"
|
"\txaddl %0, (%1)\n"
|
||||||
"\tincl %0\n"
|
"\tincl %0\n"
|
||||||
:"=r" (ret)
|
:"=r" (ret)
|
||||||
:"r" (Addend), "0" (1)
|
:"r" (Addend), "0" (1)
|
||||||
: "memory"
|
: "memory"
|
||||||
);
|
);
|
||||||
#elif defined(_M_PPC)
|
#elif defined(_M_PPC)
|
||||||
ret = *Addend;
|
ret = *Addend;
|
||||||
ret = InterlockedExchangeAdd( Addend, ret + 1 );
|
ret = InterlockedExchangeAdd( Addend, ret + 1 );
|
||||||
#else
|
#else
|
||||||
#error Unknown compiler for inline assembler
|
#error Unknown compiler for inline assembler
|
||||||
#endif
|
#endif
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* InterlockedDecrement *
|
* InterlockedDecrement *
|
||||||
* *
|
* *
|
||||||
* InterlockedDecrement adds -1 to a long variable and returns *
|
* InterlockedDecrement adds -1 to a long variable and returns *
|
||||||
* the resulting decremented value. *
|
* the resulting decremented value. *
|
||||||
* *
|
* *
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
|
|
||||||
LONG
|
LONG
|
||||||
STDCALL
|
STDCALL
|
||||||
InterlockedDecrement(LPLONG lpAddend)
|
InterlockedDecrement(LPLONG lpAddend)
|
||||||
{
|
{
|
||||||
long ret;
|
long ret;
|
||||||
#ifdef _M_IX86
|
#ifdef _M_IX86
|
||||||
__asm__
|
__asm__
|
||||||
(
|
(
|
||||||
"\tlock\n" /* for SMP systems */
|
"\tlock\n" /* for SMP systems */
|
||||||
"\txaddl %0, (%1)\n"
|
"\txaddl %0, (%1)\n"
|
||||||
"\tdecl %0\n"
|
"\tdecl %0\n"
|
||||||
:"=r" (ret)
|
:"=r" (ret)
|
||||||
:"r" (lpAddend), "0" (-1)
|
:"r" (lpAddend), "0" (-1)
|
||||||
: "memory"
|
: "memory"
|
||||||
);
|
);
|
||||||
#elif defined(_M_PPC)
|
#elif defined(_M_PPC)
|
||||||
ret = *lpAddend;
|
ret = *lpAddend;
|
||||||
ret = InterlockedExchangeAdd( lpAddend, ret - 1 );
|
ret = InterlockedExchangeAdd( lpAddend, ret - 1 );
|
||||||
#else
|
#else
|
||||||
#error Unknown compiler for inline assembler
|
#error Unknown compiler for inline assembler
|
||||||
#endif
|
#endif
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* InterlockedExchange
|
* InterlockedExchange
|
||||||
*
|
*
|
||||||
* Atomically exchanges a pair of values.
|
* Atomically exchanges a pair of values.
|
||||||
*
|
*
|
||||||
* RETURNS
|
* RETURNS
|
||||||
* Prior value of value pointed to by Target
|
* Prior value of value pointed to by Target
|
||||||
*/
|
*/
|
||||||
|
|
||||||
LONG
|
LONG
|
||||||
STDCALL
|
STDCALL
|
||||||
InterlockedExchange(LPLONG target, LONG value )
|
InterlockedExchange(LPLONG target, LONG value )
|
||||||
{
|
{
|
||||||
long ret;
|
long ret;
|
||||||
#ifdef _M_IX86
|
#ifdef _M_IX86
|
||||||
__asm__ ( /* lock for SMP systems */
|
__asm__ ( /* lock for SMP systems */
|
||||||
"lock\n\txchgl %0,(%1)"
|
"lock\n\txchgl %0,(%1)"
|
||||||
:"=r" (ret):"r" (target), "0" (value):"memory" );
|
:"=r" (ret):"r" (target), "0" (value):"memory" );
|
||||||
#elif defined(_M_PPC)
|
#elif defined(_M_PPC)
|
||||||
do {
|
do {
|
||||||
ret = *(volatile LONG *)target;
|
ret = *(volatile LONG *)target;
|
||||||
} while( InterlockedCompareExchange( target, value, ret ) != ret );
|
} while( InterlockedCompareExchange( target, value, ret ) != ret );
|
||||||
#else
|
#else
|
||||||
#error Unknown compiler for inline assembler
|
#error Unknown compiler for inline assembler
|
||||||
#endif
|
#endif
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* InterlockedCompareExchange
|
* InterlockedCompareExchange
|
||||||
*
|
*
|
||||||
* Atomically compares Destination and Comperand, and if found equal exchanges
|
* Atomically compares Destination and Comperand, and if found equal exchanges
|
||||||
* the value of Destination with Exchange
|
* the value of Destination with Exchange
|
||||||
*
|
*
|
||||||
* RETURNS
|
* RETURNS
|
||||||
* Prior value of value pointed to by Destination
|
* Prior value of value pointed to by Destination
|
||||||
*/
|
*/
|
||||||
LONG
|
LONG
|
||||||
STDCALL
|
STDCALL
|
||||||
InterlockedCompareExchange(
|
InterlockedCompareExchange(
|
||||||
LPLONG Destination,
|
LPLONG Destination,
|
||||||
LONG Exchange,
|
LONG Exchange,
|
||||||
LONG Comperand )
|
LONG Comperand )
|
||||||
{
|
{
|
||||||
LONG ret;
|
LONG ret;
|
||||||
#ifdef _M_IX86
|
#ifdef _M_IX86
|
||||||
__asm__ __volatile__( "lock; cmpxchgl %2,(%1)"
|
__asm__ __volatile__( "lock; cmpxchgl %2,(%1)"
|
||||||
: "=a" (ret) : "r" (Destination), "r" (Exchange), "0" (Comperand) : "memory" );
|
: "=a" (ret) : "r" (Destination), "r" (Exchange), "0" (Comperand) : "memory" );
|
||||||
#elif defined(_M_PPC)
|
#elif defined(_M_PPC)
|
||||||
__asm__ __volatile__ ("sync\n"
|
__asm__ __volatile__ ("sync\n"
|
||||||
"1: lwarx %0,0,%1\n"
|
"1: lwarx %0,0,%1\n"
|
||||||
" subf. %0,%2,%0\n"
|
" subf. %0,%2,%0\n"
|
||||||
" bne 2f\n"
|
" bne 2f\n"
|
||||||
" stwcx. %3,0,%1\n"
|
" stwcx. %3,0,%1\n"
|
||||||
" bne- 1b\n"
|
" bne- 1b\n"
|
||||||
"2: isync"
|
"2: isync"
|
||||||
: "=&r" (ret)
|
: "=&r" (ret)
|
||||||
: "b" (Destination), "r" (Comperand), "r" (Exchange)
|
: "b" (Destination), "r" (Comperand), "r" (Exchange)
|
||||||
: "cr0", "memory");
|
: "cr0", "memory");
|
||||||
#else
|
#else
|
||||||
#error Unknown compiler for inline assembler
|
#error Unknown compiler for inline assembler
|
||||||
#endif
|
#endif
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* InterlockedExchangeAdd
|
* InterlockedExchangeAdd
|
||||||
*
|
*
|
||||||
* Atomically adds Increment to Addend and returns the previous value of
|
* Atomically adds Increment to Addend and returns the previous value of
|
||||||
* Addend
|
* Addend
|
||||||
*
|
*
|
||||||
* RETURNS
|
* RETURNS
|
||||||
* Prior value of value pointed to by Addend
|
* Prior value of value pointed to by Addend
|
||||||
*/
|
*/
|
||||||
LONG
|
LONG
|
||||||
STDCALL
|
STDCALL
|
||||||
InterlockedExchangeAdd(
|
InterlockedExchangeAdd(
|
||||||
PLONG Addend,
|
PLONG Addend,
|
||||||
LONG Increment
|
LONG Increment
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
LONG ret;
|
LONG ret;
|
||||||
#ifdef _M_IX86
|
#ifdef _M_IX86
|
||||||
__asm__ ( /* lock for SMP systems */
|
__asm__ ( /* lock for SMP systems */
|
||||||
"lock\n\t"
|
"lock\n\t"
|
||||||
"xaddl %0,(%1)"
|
"xaddl %0,(%1)"
|
||||||
:"=r" (ret)
|
:"=r" (ret)
|
||||||
:"r" (Addend), "0" (Increment)
|
:"r" (Addend), "0" (Increment)
|
||||||
:"memory" );
|
:"memory" );
|
||||||
#elif defined(_M_PPC)
|
#elif defined(_M_PPC)
|
||||||
LONG newval;
|
LONG newval;
|
||||||
do {
|
do {
|
||||||
ret = *(volatile LONG *)Addend;
|
ret = *(volatile LONG *)Addend;
|
||||||
newval = ret + Increment;
|
newval = ret + Increment;
|
||||||
} while (InterlockedCompareExchange(Addend, ret, newval) != ret);
|
} while (InterlockedCompareExchange(Addend, ret, newval) != ret);
|
||||||
#else
|
#else
|
||||||
#error Unknown compiler for inline assembler
|
#error Unknown compiler for inline assembler
|
||||||
#endif
|
#endif
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
4
reactos/lib/intrlck/intrlck.xml
Normal file
4
reactos/lib/intrlck/intrlck.xml
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
<module name="intrlck" type="staticlibrary">
|
||||||
|
<define name="__USE_W32API" />
|
||||||
|
<file>intrlck.c</file>
|
||||||
|
</module>
|
|
@ -117,6 +117,7 @@
|
||||||
<library>kernel32_base</library>
|
<library>kernel32_base</library>
|
||||||
<library>pseh</library>
|
<library>pseh</library>
|
||||||
<library>rosrtl</library>
|
<library>rosrtl</library>
|
||||||
|
<library>intrlck</library>
|
||||||
<library>ntdll</library>
|
<library>ntdll</library>
|
||||||
<linkerflag>-lgcc</linkerflag>
|
<linkerflag>-lgcc</linkerflag>
|
||||||
<linkerflag>-nostartfiles</linkerflag>
|
<linkerflag>-nostartfiles</linkerflag>
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
<define name="_NTOSKRNL_" />
|
<define name="_NTOSKRNL_" />
|
||||||
<library>rtl</library>
|
<library>rtl</library>
|
||||||
<library>rosrtl</library>
|
<library>rosrtl</library>
|
||||||
|
<library>intrlck</library>
|
||||||
<library>string</library>
|
<library>string</library>
|
||||||
<linkerflag>-lgcc</linkerflag>
|
<linkerflag>-lgcc</linkerflag>
|
||||||
<directory name="csr">
|
<directory name="csr">
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
</directory>
|
</directory>
|
||||||
<directory name="misc">
|
<directory name="misc">
|
||||||
<file>devmode.c</file>
|
<file>devmode.c</file>
|
||||||
<file>intrlck.c</file>
|
|
||||||
<file>logfont.c</file>
|
<file>logfont.c</file>
|
||||||
<file>qsort.c</file>
|
<file>qsort.c</file>
|
||||||
</directory>
|
</directory>
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
<define name="__USE_W32API" />
|
<define name="__USE_W32API" />
|
||||||
<define name="_WIN32_WINNT">0x0600</define>
|
<define name="_WIN32_WINNT">0x0600</define>
|
||||||
<define name="WINVER">0x0501</define>
|
<define name="WINVER">0x0501</define>
|
||||||
<library>rosrtl</library>
|
<library>intrlck</library>
|
||||||
<library>ntdll</library>
|
<library>ntdll</library>
|
||||||
<library>smdll</library>
|
<library>smdll</library>
|
||||||
<directory name="api">
|
<directory name="api">
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue