[pypy-commit] pypy concurrent-marksweep: Oups, forgot to add this file. It's needed in debug_lltrace.

arigo noreply at buildbot.pypy.org
Sat Oct 22 21:40:32 CEST 2011


Author: Armin Rigo <arigo at tunes.org>
Branch: concurrent-marksweep
Changeset: r48344:eb5d8279f60e
Date: 2011-10-22 21:36 +0200
http://bitbucket.org/pypy/pypy/changeset/eb5d8279f60e/

Log:	Oups, forgot to add this file. It's needed in debug_lltrace.

diff --git a/pypy/translator/c/src/atomic_ops.h b/pypy/translator/c/src/atomic_ops.h
new file mode 100644
--- /dev/null
+++ b/pypy/translator/c/src/atomic_ops.h
@@ -0,0 +1,45 @@
+
+
+/* "compiler fence" for preventing reordering of loads/stores to
+   non-volatiles */
+#define CFENCE          asm volatile ("":::"memory")
+
+
+#ifdef __llvm__
+#  define HAS_SYNC_BOOL_COMPARE_AND_SWAP
+#endif
+
+#ifdef __GNUC__
+#  if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)
+#    define HAS_SYNC_BOOL_COMPARE_AND_SWAP
+#  endif
+#endif
+
+
+#ifdef HAS_SYNC_BOOL_COMPARE_AND_SWAP
+#  define bool_cas __sync_bool_compare_and_swap
+#else
+/* x86 (32 bits and 64 bits) */
+static inline _Bool
+bool_cas(volatile unsigned long* ptr, unsigned long old, unsigned long _new)
+{
+    unsigned long prev;
+    asm volatile("lock;"
+#if defined(__amd64__)
+                 "cmpxchgq %1, %2;"
+#else
+                 "cmpxchgl %1, %2;"
+#endif
+                 : "=a"(prev)
+                 : "q"(_new), "m"(*ptr), "a"(old)
+                 : "memory");
+    return prev == old;
+}
+/* end */
+#endif
+
+
+static inline void spinloop(void)
+{
+  asm volatile ("pause");
+}


More information about the pypy-commit mailing list