[pypy-commit] pypy stmgc-c4: in-progress

arigo noreply at buildbot.pypy.org
Sat Jun 29 20:44:03 CEST 2013


Author: Armin Rigo <arigo at tunes.org>
Branch: stmgc-c4
Changeset: r65105:dadb9e0f175c
Date: 2013-06-29 20:43 +0200
http://bitbucket.org/pypy/pypy/changeset/dadb9e0f175c/

Log:	in-progress

diff --git a/rpython/translator/c/src/debug_print.c b/rpython/translator/c/src/debug_print.c
--- a/rpython/translator/c/src/debug_print.c
+++ b/rpython/translator/c/src/debug_print.c
@@ -137,11 +137,13 @@
 
 #ifdef RPY_STM
 # include <src_stm/atomic_ops.h>
+# include <src_stm/fprintcolor.h>
 #else
   typedef long revision_t;
 # define bool_cas(vp, o, n) (*(vp)=(n), 1)
+# define dprintfcolor() 0
 #endif
-static volatile revision_t threadcounter = 0;
+static revision_t threadcounter = 0;
 
 static void _prepare_display_colors(void)
 {
@@ -160,7 +162,14 @@
     }
     else {
         /* tty output */
-        int color = 31 + (int)(counter % 7);
+        /* If we have STM and it is compiled in debug mode, share
+           the color to use.  It avoids endless confusion caused by
+           each thread using two independent colors for the two
+           debugging outputs. */
+        int color = dprintfcolor();
+        if (color == 0) {
+            color = 31 + (int)(counter % 7);
+        }
         sprintf(debug_start_colors_1, "\033[%dm%d# \033[1m",
                 color, (int)counter);
         sprintf(debug_start_colors_2, "\033[%dm%d# ",
diff --git a/rpython/translator/c/src/entrypoint.c b/rpython/translator/c/src/entrypoint.c
--- a/rpython/translator/c/src/entrypoint.c
+++ b/rpython/translator/c/src/entrypoint.c
@@ -14,11 +14,6 @@
 #include <stdlib.h>
 #include <stdio.h>
 
-#ifdef RPY_STM
-#include <src/debug_print.h>
-#include "src_stm/et.c"
-#endif
-
 #ifdef __GNUC__
 /* Hack to prevent this function from being inlined.  Helps asmgcc
    because the main() function has often a different prologue/epilogue. */
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
@@ -17,10 +17,10 @@
 
 #ifdef RPY_STM
 # include "src_stm/atomic_ops.h"
-static volatile Unsigned pypy_debug_alloc_lock = 0;
+static revision_t pypy_debug_alloc_lock = 0;
 #else
-# define stm_lock_acquire(lock)  /* nothing */
-# define stm_lock_release(lock)  /* nothing */
+# define spinlock_acquire(lock, targetvalue)  /* nothing */
+# define spinlock_release(lock)               /* nothing */
 #endif
 
 void pypy_debug_alloc_start(void *addr, const char *funcname)
@@ -29,23 +29,23 @@
   RPyAssert(p, "out of memory");
   p->addr = addr;
   p->funcname = funcname;
-  stm_lock_acquire(pypy_debug_alloc_lock);
+  spinlock_acquire(pypy_debug_alloc_lock, '+');
   p->next = pypy_debug_alloc_list;
   pypy_debug_alloc_list = p;
-  stm_lock_release(pypy_debug_alloc_lock);
+  spinlock_release(pypy_debug_alloc_lock);
 }
 
 void pypy_debug_alloc_stop(void *addr)
 {
   struct pypy_debug_alloc_s **p;
-  stm_lock_acquire(pypy_debug_alloc_lock);
+  spinlock_acquire(pypy_debug_alloc_lock, '-');
   for (p = &pypy_debug_alloc_list; *p; p = &((*p)->next))
     if ((*p)->addr == addr)
       {
         struct pypy_debug_alloc_s *dying;
         dying = *p;
         *p = dying->next;
-        stm_lock_release(pypy_debug_alloc_lock);
+        spinlock_release(pypy_debug_alloc_lock);
         free(dying);
         return;
       }
diff --git a/rpython/translator/stm/src_stm/fprintcolor.c b/rpython/translator/stm/src_stm/fprintcolor.c
--- a/rpython/translator/stm/src_stm/fprintcolor.c
+++ b/rpython/translator/stm/src_stm/fprintcolor.c
@@ -25,12 +25,8 @@
 static __thread revision_t tcolor = 0;
 static revision_t tnextid = 0;
 
-
-int threadcolor_printf(const char *format, ...)
+int dprintfcolor(void)
 {
-    char buffer[2048];
-    va_list ap;
-    int result;
     if (tcolor == 0) {
         while (1) {
             tcolor = tnextid;
@@ -39,7 +35,15 @@
         }
         tcolor = 31 + tcolor % 6;
     }
-    int size = (int)sprintf(buffer, "\033[%dm", (int)tcolor);
+    return tcolor;
+}
+
+int threadcolor_printf(const char *format, ...)
+{
+    char buffer[2048];
+    va_list ap;
+    int result;
+    int size = (int)sprintf(buffer, "\033[%dm", dprintfcolor());
     assert(size >= 0);
 
     va_start(ap, format);
diff --git a/rpython/translator/stm/src_stm/fprintcolor.h b/rpython/translator/stm/src_stm/fprintcolor.h
--- a/rpython/translator/stm/src_stm/fprintcolor.h
+++ b/rpython/translator/stm/src_stm/fprintcolor.h
@@ -10,6 +10,7 @@
 #ifdef _GC_DEBUG
 
 #define dprintf(args)   threadcolor_printf args
+int dprintfcolor(void);
 
 int threadcolor_printf(const char *format, ...)
      __attribute__((format (printf, 1, 2)));
@@ -17,5 +18,6 @@
 #else
 
 #define dprintf(args)   do { } while(0)
+#define dprintfcolor()  0
 
 #endif
diff --git a/rpython/translator/stm/src_stm/revision b/rpython/translator/stm/src_stm/revision
--- a/rpython/translator/stm/src_stm/revision
+++ b/rpython/translator/stm/src_stm/revision
@@ -1,1 +1,1 @@
-c856b6a0d157
+c856b6a0d157+
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
@@ -9,4 +9,5 @@
     include_dirs = [cdir, cdir2],
     includes = ['src_stm/stmgc.h'],
     pre_include_bits = ['#define RPY_STM 1'],
+    separate_module_sources = ['\n#include "src_stm/stmgc.c"\n'],
 )


More information about the pypy-commit mailing list