diff options
author | Michael Meeks <michael.meeks@novell.com> | 2011-01-28 15:17:58 +0000 |
---|---|---|
committer | Michael Meeks <michael.meeks@novell.com> | 2011-01-28 15:17:58 +0000 |
commit | d7f50df6521aff8b934fdd274408b5b031ad8372 (patch) | |
tree | 78ca7b737177fac37be53cebcc58975e6e6b89a5 | |
parent | 5b3360fa4556c58e594d5eef6470bbaf2bc1174d (diff) |
further simplify old-style interlocked inc/dec
-rw-r--r-- | sal/osl/unx/interlck.c | 40 |
1 files changed, 14 insertions, 26 deletions
diff --git a/sal/osl/unx/interlck.c b/sal/osl/unx/interlck.c index f47ad99beed8..569f17ab1c83 100644 --- a/sal/osl/unx/interlck.c +++ b/sal/osl/unx/interlck.c @@ -46,52 +46,40 @@ extern int osl_isSingleCPU; /*****************************************************************************/ oslInterlockedCount SAL_CALL osl_incrementInterlockedCount(oslInterlockedCount* pCount) { - register oslInterlockedCount nCount asm("%eax"); + // Fast case for old, slow, single CPU Intel machines for whom + // interlocking is a performance nightmare. + if ( osl_isSingleCPU ) { + register oslInterlockedCount nCount asm("%eax"); - nCount = 1; + nCount = 1; - if ( osl_isSingleCPU ) { __asm__ __volatile__ ( "xaddl %0, %1\n\t" : "+r" (nCount), "+m" (*pCount) : /* nothing */ : "memory"); + return ++nCount; } - else { - __asm__ __volatile__ ( - "lock\n\t" - "xaddl %0, %1\n\t" - : "+r" (nCount), "+m" (*pCount) - : /* nothing */ - : "memory"); - } - - return ++nCount; + else + return __sync_add_and_fetch (pCount, 1); } oslInterlockedCount SAL_CALL osl_decrementInterlockedCount(oslInterlockedCount* pCount) { - register oslInterlockedCount nCount asm("%eax"); + if ( osl_isSingleCPU ) { + register oslInterlockedCount nCount asm("%eax"); - nCount = -1; + nCount = -1; - if ( osl_isSingleCPU ) { __asm__ __volatile__ ( "xaddl %0, %1\n\t" : "+r" (nCount), "+m" (*pCount) : /* nothing */ : "memory"); + return --nCount; } - else { - __asm__ __volatile__ ( - "lock\n\t" - "xaddl %0, %1\n\t" - : "+r" (nCount), "+m" (*pCount) - : /* nothing */ - : "memory"); - } - - return --nCount; + else + return __sync_sub_and_fetch (pCount, 1); } #elif defined ( GCC ) |