1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
diff --git a/src/lib/libumem/sol_compat.h b/src/lib/libumem/sol_compat.h
index 858a026..9250e18 100644
--- a/src/lib/libumem/sol_compat.h
+++ b/src/lib/libumem/sol_compat.h
@@ -176,23 +176,15 @@ static INLINE uint_t ec_atomic_cas(uint_t *mem, uint_t with, uint_t cmp)
: "memory");
return prev;
}
-# endif
-
-# ifndef ec_atomic_inc
-static INLINE uint_t ec_atomic_inc(uint_t *mem)
+# elif defined(__sparc__) && defined(__GNUC__)
+static INLINE uint_t ec_atomic_cas(uint_t *mem, uint_t with, uint_t cmp)
{
- register uint_t last;
- do {
- last = *mem;
- } while (ec_atomic_cas(mem, last+1, last) != last);
- return ++last;
+ __asm volatile ("cas [%3],%2,%0"
+ : "+r"(with), "=m"(*(mem))
+ : "r"(cmp), "r"(mem), "m"(*(mem)) );
+ return with;
}
# endif
-# ifndef ec_atomic_inc64
- /* yeah, it's not great. It's only used to bump failed allocation
- * counts, so it is not critical right now. */
-# define ec_atomic_inc64(a) (*a)++
-# endif
#endif
@@ -208,8 +200,37 @@ static INLINE uint_t ec_atomic_inc(uint_t *mem)
#define ISP2(x) (((x) & ((x) - 1)) == 0)
/* beware! umem only uses these atomic adds for incrementing by 1 */
+#if defined(_WIN32) || (defined(__GNUC__) && \
+ (defined(__i386__) || defined(__x86_64__) || defined(__sparc__)))
+# ifndef ec_atomic_inc
+static INLINE uint_t ec_atomic_inc(uint_t *mem)
+{
+ register uint_t last;
+ do {
+ last = *mem;
+ } while (ec_atomic_cas(mem, last+1, last) != last);
+ return ++last;
+}
+# endif
+# ifndef ec_atomic_inc64
+ /* yeah, it's not great. It's only used to bump failed allocation
+ * counts, so it is not critical right now. */
+# define ec_atomic_inc64(a) (*a)++
+# endif
+
#define atomic_add_64(lvalptr, delta) ec_atomic_inc64(lvalptr)
#define atomic_add_32_nv(a, b) ec_atomic_inc(a)
+#elif defined(__powerpc) || defined(__powerpc__) ||\
+ defined(__powerpc64) || defined(__powerpc64__)
+# ifndef ec_atomic_inc64
+# define ec_atomic_inc64(a) (*a)++
+# endif
+#define atomic_add_64(lvalptr, delta) ec_atomic_inc64(lvalptr)
+#define atomic_add_32_nv(a, b) ec_atomic_inc(a)
+#else
+extern uint32_t atomic_add_32_nv(volatile uint32_t *, int32_t);
+extern void atomic_add_64(volatile uint64_t *, int64_t);
+#endif
#ifndef NANOSEC
#define NANOSEC 1000000000
|