Use platform-provided atomic operations in place of inline assembly to increase porta...
authormrowe@apple.com <mrowe@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Jan 2008 07:55:49 +0000 (07:55 +0000)
committermrowe@apple.com <mrowe@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Jan 2008 07:55:49 +0000 (07:55 +0000)
Reviewed by Maciej Stachowiak.

* platform/Threading.h:
(WebCore::atomicIncrement):
(WebCore::atomicDecrement):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@29150 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog
WebCore/platform/Threading.h

index 580832e889c8c2edea89c65388567b9a7f1e48ea..ebde3515f0e7db2ee41a61b3c34fceb119e72832 100644 (file)
@@ -1,3 +1,14 @@
+2008-01-03  Mark Rowe  <mrowe@apple.com>
+
+        Reviewed by Maciej Stachowiak.
+
+        Use platform-provided atomic operations in place of inline assembly to
+        increase portability.
+
+        * platform/Threading.h:
+        (WebCore::atomicIncrement):
+        (WebCore::atomicDecrement):
+
 2008-01-03  Oliver Hunt  <oliver@apple.com>
 
         Reviewed by Maciej.
index 08981b6f2a74e19976693f7de3b4b0a0c19eec59..765c9aefdfd50bf6bf75f3a75808de938f052f10 100644 (file)
 
 #if PLATFORM(WIN_OS)
 #include <windows.h>
+#elif PLATFORM(DARWIN)
+#include <libkern/OSAtomic.h>
+#elif COMPILER(GCC)
+#if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 2))
+#include <ext/atomicity.h>
+#else
+#include <bits/atomicity.h>
+#endif
 #endif
 
 #if USE(PTHREADS)
@@ -160,69 +168,21 @@ private:
 #if PLATFORM(WIN_OS)
 #define WTF_USE_LOCKFREE_THREADSAFESHARED 1
 
-inline void atomicIncrement(int volatile* addened) { InterlockedIncrement(reinterpret_cast<long volatile*>(addened)); }
-inline int atomicDecrement(int volatile* addened) { return InterlockedDecrement(reinterpret_cast<long volatile*>(addened)); }
+inline void atomicIncrement(int volatile* addend) { InterlockedIncrement(reinterpret_cast<long volatile*>(addend)); }
+inline int atomicDecrement(int volatile* addend) { return InterlockedDecrement(reinterpret_cast<long volatile*>(addend)); }
 
-#elif COMPILER(GCC) && (PLATFORM(X86) || PLATFORM(X86_64) || PLATFORM(PPC) || PLATFORM(PPC64))
+#elif PLATFORM(DARWIN)
 #define WTF_USE_LOCKFREE_THREADSAFESHARED 1
 
-inline void atomicIncrement(int volatile* addend)
-{
-#if PLATFORM(X86) || PLATFORM(X86_64)
-    __asm__(
-        "lock\n\t"
-        "incl %0":
-        "=m"(*addend): // output (%0)
-        "m"(*addend): // input (%1)
-        "cc"
-    );
-#else
-    int tmp;
-    __asm__(
-        "0:\n\t"
-        "lwarx %1, 0, %2\n\t"
-        "addi %1, %1, 1\n\t"
-        "stwcx. %1, 0, %2\n\t"
-        "bne- 0b":
-
-        "=m"(*addend), "=&b"(tmp):
-        "r"(addend), "m"(*addend):
-        "cc"
-    );
-#endif
-}
+inline void atomicIncrement(int volatile* addend) { OSAtomicIncrement32Barrier(addend); }
+inline int atomicDecrement(int volatile* addend) { return OSAtomicDecrement32Barrier(addend); }
+
+#elif COMPILER(GCC)
+#define WTF_USE_LOCKFREE_THREADSAFESHARED 1
+
+inline void atomicIncrement(int volatile* addend) { __gnu_cxx::__atomic_add(addend, 1); }
+inline int atomicDecrement(int volatile* addend) { return __gnu_cxx::__exchange_and_add(addend, -1) - 1; }
 
-inline int atomicDecrement(int volatile* addend)
-{
-#if PLATFORM(X86) || PLATFORM(X86_64)
-    int readval = 0;
-    __asm__ __volatile__
-    (
-        "lock\n\t"
-        "xadd %1, %0":
-        "=m"(*addend), "=r"(readval): // outputs (%0, %1)
-        "m"(*addend), "1"(-1): // inputs (%2, %3 == %1)
-        "memory", "cc" // clobbers
-    );
-    return readval - 1;
-#else
-    int readval;
-    __asm__ __volatile__(
-        "sync\n\t"
-        "0:\n\t"
-        "lwarx %1, 0, %2\n\t"
-        "addi %1, %1, -1\n\t"
-        "stwcx. %1, 0, %2\n\t"
-        "bne- 0b\n\t"
-        "isync":
-
-        "=m"(*addend), "=&b"(readval):
-        "r"(addend), "m"(*addend):
-        "memory", "cc"
-    );
-    return readval;
-#endif
-}
 #endif
 
 template<class T> class ThreadSafeShared : Noncopyable {