[Libreoffice-commits] .: sal/osl

Michael Meeks mmeeks at kemper.freedesktop.org
Fri Jan 28 07:18:33 PST 2011


 sal/osl/unx/interlck.c |   40 ++++++++++++++--------------------------
 1 file changed, 14 insertions(+), 26 deletions(-)

New commits:
commit c016d1bdd2304f8bdff31bd1f528d7f3b84acd29
Author: Michael Meeks <michael.meeks at novell.com>
Date:   Fri Jan 28 15:17:58 2011 +0000

    further simplify old-style interlocked inc/dec

diff --git a/sal/osl/unx/interlck.c b/sal/osl/unx/interlck.c
index d339f21..71f8d9c 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 )


More information about the Libreoffice-commits mailing list