mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
Update atomic increment/decrement
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@26369 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
aeabafcf12
commit
0dca6da5fb
2 changed files with 53 additions and 14 deletions
|
@ -1,3 +1,9 @@
|
|||
2008-03-20 David Chisnall <csdavec@swansea.ac.uk
|
||||
|
||||
* Source/NSObject.m: Changed atomic increment/decrement for intel
|
||||
to simpler (perhaps marginally faster) code, also added atomic
|
||||
increment/decrement for PPC.
|
||||
|
||||
2008-03-20 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/win32/GSRunLoopCtxt.m: Fix bad function call (bug #22676)
|
||||
|
|
|
@ -230,7 +230,7 @@ typedef int32_t volatile *gsatomic_t;
|
|||
#endif
|
||||
|
||||
|
||||
#if defined(__linux__) && (defined(__i386__) || defined(__x86_64__))
|
||||
#elif defined(__linux__) && (defined(__i386__) || defined(__x86_64__))
|
||||
/* Set up atomic read, increment and decrement for intel style linux
|
||||
*/
|
||||
|
||||
|
@ -241,26 +241,59 @@ typedef int32_t volatile *gsatomic_t;
|
|||
static __inline__ int
|
||||
GSAtomicIncrement(gsatomic_t X)
|
||||
{
|
||||
int i = 1;
|
||||
__asm__ __volatile__(
|
||||
"lock ; xaddl %0, %1;"
|
||||
:"=r"(i)
|
||||
:"m"(*X), "0"(i));
|
||||
return i + 1;
|
||||
__asm__ __volatile__ (
|
||||
"lock addl $1, %0"
|
||||
:"=m" (*X));
|
||||
return *X;
|
||||
}
|
||||
|
||||
static __inline__ int
|
||||
GSAtomicDecrement(gsatomic_t X)
|
||||
{
|
||||
int i = -1;
|
||||
__asm__ __volatile__(
|
||||
"lock ; xaddl %0, %1;"
|
||||
:"=r"(i)
|
||||
:"m"(*X), "0"(i));
|
||||
return i - 1;
|
||||
__asm__ __volatile__ (
|
||||
"lock subl $1, %0"
|
||||
:"=m" (*X));
|
||||
return *X;
|
||||
}
|
||||
|
||||
#elif defined(__PPC__)
|
||||
|
||||
typedef int32_t volatile *gsatomic_t;
|
||||
|
||||
#define GSATOMICREAD(X) (*(X))
|
||||
|
||||
static __inline__ int
|
||||
GSAtomicIncrement(gsatomic_t X)
|
||||
{
|
||||
int tmp;
|
||||
__asm__ __volatile__ (
|
||||
"modified:"
|
||||
"lwarx %0,0,%1 \n"
|
||||
"addic %0,%0,1 \n"
|
||||
"stwcx. %0,0,%1 \n"
|
||||
"bne- modified \n"
|
||||
:"=&r" (tmp)
|
||||
:"r" (X)
|
||||
:"cc", "memory");
|
||||
return *X;
|
||||
}
|
||||
|
||||
static __inline__ int
|
||||
GSAtomicDecrement(gsatomic_t X)
|
||||
{
|
||||
int tmp;
|
||||
__asm__ __volatile__ (
|
||||
"modified:"
|
||||
"lwarx %0,0,%1 \n"
|
||||
"addic %0,%0,-1 \n"
|
||||
"stwcx. %0,0,%1 \n"
|
||||
"bne- modified \n"
|
||||
:"=&r" (tmp)
|
||||
:"r" (X)
|
||||
:"cc", "memory");
|
||||
return *X;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(REFCNT_LOCAL) && !defined(GSATOMICREAD)
|
||||
|
|
Loading…
Reference in a new issue