Author: Armin Rigo <[email protected]>
Branch: stmgc-c7
Changeset: r69801:4b10a8645bb0
Date: 2014-03-08 13:04 +0100
http://bitbucket.org/pypy/pypy/changeset/4b10a8645bb0/

Log:    progress!

diff --git a/rpython/translator/c/src/mem.c b/rpython/translator/c/src/mem.c
--- a/rpython/translator/c/src/mem.c
+++ b/rpython/translator/c/src/mem.c
@@ -45,7 +45,7 @@
 static struct pypy_debug_alloc_s *pypy_debug_alloc_list = NULL;
 
 #ifdef RPY_STM
-# include "src_stm/atomic_ops.h"
+// spinlock_acquire/spinlock_release defined in ../../stm/src_stm/stmgcintf.h
 static revision_t pypy_debug_alloc_lock = 0;
 #else
 # define spinlock_acquire(lock, targetvalue)  /* nothing */
diff --git a/rpython/translator/stm/src_stm/stmgcintf.c 
b/rpython/translator/stm/src_stm/stmgcintf.c
new file mode 100644
--- /dev/null
+++ b/rpython/translator/stm/src_stm/stmgcintf.c
@@ -0,0 +1,17 @@
+#include "src_stm/stmgcintf.h"
+
+__thread struct stm_thread_local_s stm_thread_local;
+
+extern Signed pypy_stmcb_size(void*);
+extern void pypy_stmcb_trace(void*, void(*)(void*));
+
+inline size_t stmcb_size(struct object_s *obj) {
+    return pypy_stmcb_size(obj);
+}
+
+inline void stmcb_trace(struct object_s *obj, void visit(object_t **)) {
+    pypy_stmcb_trace(obj, (void(*)(void*))visit);
+}
+
+/* "include" the stmgc.c file here */
+#include "src_stm/stmgc.c"
diff --git a/rpython/translator/stm/src_stm/stmgcintf.h 
b/rpython/translator/stm/src_stm/stmgcintf.h
new file mode 100644
--- /dev/null
+++ b/rpython/translator/stm/src_stm/stmgcintf.h
@@ -0,0 +1,27 @@
+/* meant to be #included after src_stm/stmgc.h */
+
+#include "stmgc.h"
+#include "stm/atomic.h"    /* for spin_loop() and write_fence() */
+
+extern __thread struct stm_thread_local_s stm_thread_local;
+
+
+#if 0    /* fprinting versions */
+# define spinlock_acquire(lock, targetvalue)                            \
+    do { if (__sync_bool_compare_and_swap(&(lock), 0, (targetvalue))) { \
+             dprintf(("<<< locked %d\n", (int)targetvalue));            \
+             break;                                                     \
+         }                                                              \
+         do { spin_loop(); } while (lock);                              \
+    } while (1)
+# define spinlock_release(lock)                                         \
+    do { dprintf(("unlocked >>>\n")); write_fence();                    \
+         assert((lock) != 0); (lock) = 0; } while (0)
+#else
+# define spinlock_acquire(lock, targetvalue)                                 \
+    do { if (__sync_bool_compare_and_swap(&(lock), 0, (targetvalue))) break; \
+         do { spin_loop(); } while (lock);                                   \
+    } while (1)
+# define spinlock_release(lock)                                 \
+    do { write_fence(); assert((lock) != 0); (lock) = 0; } while (0)
+#endif
diff --git a/rpython/translator/stm/stmgcintf.py 
b/rpython/translator/stm/stmgcintf.py
--- a/rpython/translator/stm/stmgcintf.py
+++ b/rpython/translator/stm/stmgcintf.py
@@ -6,33 +6,14 @@
 
 cdir = os.path.abspath(os.path.join(cdir2, '..', 'stm'))
 
-separate_source = '''
-//#define _GC_DEBUG   2       /* XXX move elsewhere */
-
-#include "src_stm/stmgc.h"
-
-__thread struct stm_thread_local_s stm_thread_local;
-
-extern Signed pypy_stmcb_size(void*);
-extern void pypy_stmcb_trace(void*, void(*)(void*));
-
-inline size_t stmcb_size(struct object_s *obj) {
-    return pypy_stmcb_size(obj);
-}
-
-inline void stmcb_trace(struct object_s *obj, void visit(object_t **)) {
-    pypy_stmcb_trace(obj, (void(*)(void*))visit);
-}
-
-#include "src_stm/stmgc.c"
-'''
+_f = open(os.path.join(cdir, 'src_stm', 'stmgcintf.c'), 'r')
+separate_source = _f.read()
+_f.close()
 
 eci = ExternalCompilationInfo(
     include_dirs = [cdir, cdir2],
-    includes = ['src_stm/stmgc.h'],
+    includes = ['src_stm/stmgcintf.h'],
     pre_include_bits = ['#define RPY_STM 1'],
-    post_include_bits = [
-        'extern __thread struct stm_thread_local_s stm_thread_local;'],
     separate_module_sources = [separate_source],
 )
 
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to