Permalink
Browse files

Fix atomic add and atomic subtract. Now passes tests.

  • Loading branch information...
1 parent 3d4ab0b commit ee92ffde4afe3aa5f0e8d086fafdbd25057a364a @amejia1 amejia1 committed Jun 22, 2012
Showing with 38 additions and 0 deletions.
  1. +38 −0 xbmc/threads/Atomics.cpp
View
@@ -306,6 +306,25 @@ long AtomicAdd(volatile long* pAddr, long amount)
return amount;
}
+#elif defined(__GNUC__)
+
+long AtomicAdd(volatile long* pAddr, long amount)
+{
+ return __sync_add_and_fetch(pAddr, amount);
+}
+
+#elif defined(__x86_64__)
+
+long AtomicAdd(volatile long* pAddr, long amount)
+{
+ register long result;
+ __asm__ __volatile__ (
+ "lock/xaddq %q0, %1"
+ : "=r" (result), "=m" (*pAddr)
+ : "0" ((long) (amount)), "m" (*pAddr));
+ return *pAddr;
+}
+
#else // Linux / OSX86 (GCC)
long AtomicAdd(volatile long* pAddr, long amount)
@@ -466,6 +485,25 @@ long AtomicSubtract(volatile long* pAddr, long amount)
return amount;
}
+#elif defined(__GNUC__)
+
+long AtomicSubtract(volatile long* pAddr, long amount)
+{
+ return __sync_sub_and_fetch(pAddr, amount);
+}
+
+#elif defined(__x86_64__)
+
+long AtomicSubtract(volatile long* pAddr, long amount)
+{
+ register long result;
+ __asm__ __volatile__ (
+ "lock/xaddq %q0, %1"
+ : "=r" (result), "=m" (*pAddr)
+ : "0" ((long) (-1 * amount)), "m" (*pAddr));
+ return *pAddr;
+}
+
#else // Linux / OSX86 (GCC)
long AtomicSubtract(volatile long* pAddr, long amount)

0 comments on commit ee92ffd

Please sign in to comment.