[pypy-commit] pypy stm: (antocuni, arigo)

arigo noreply at buildbot.pypy.org
Tue Jan 17 14:52:52 CET 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: stm
Changeset: r51399:4ef670f3a925
Date: 2012-01-17 12:39 +0100
http://bitbucket.org/pypy/pypy/changeset/4ef670f3a925/

Log:	(antocuni, arigo)

	Refactored targetdemo.py to use the new interface.

	Allow debug_start/debug_print/debug_stop to work (as long as you
	don't say PYPYLOG=..:file) by making the flag thread-local.

diff --git a/pypy/translator/c/src/debug_print.c b/pypy/translator/c/src/debug_print.c
--- a/pypy/translator/c/src/debug_print.c
+++ b/pypy/translator/c/src/debug_print.c
@@ -15,8 +15,8 @@
 #include "src/profiling.h"
 #include "src/debug_print.h"
 
-long pypy_have_debug_prints = -1;
-FILE *pypy_debug_file = NULL;
+__thread long pypy_have_debug_prints = -1;
+FILE *pypy_debug_file = NULL;   /* XXX make it thread-local too? */
 static unsigned char debug_ready = 0;
 static unsigned char debug_profile = 0;
 static char *debug_start_colors_1 = "";
diff --git a/pypy/translator/c/src/debug_print.h b/pypy/translator/c/src/debug_print.h
--- a/pypy/translator/c/src/debug_print.h
+++ b/pypy/translator/c/src/debug_print.h
@@ -38,7 +38,7 @@
 void pypy_debug_stop(const char *category);
 long pypy_debug_offset(void);
 
-extern long pypy_have_debug_prints;
+extern __thread long pypy_have_debug_prints;
 extern FILE *pypy_debug_file;
 
 #define OP_LL_READ_TIMESTAMP(val) READ_TIMESTAMP(val)
diff --git a/pypy/translator/stm/test/targetdemo.py b/pypy/translator/stm/test/targetdemo.py
--- a/pypy/translator/stm/test/targetdemo.py
+++ b/pypy/translator/stm/test/targetdemo.py
@@ -1,6 +1,7 @@
 import time
 from pypy.module.thread import ll_thread
-#from pypy.translator.stm import rstm
+from pypy.rlib import rstm
+from pypy.rlib.debug import debug_print
 
 
 class Node:
@@ -15,8 +16,13 @@
     anchor      = Node(-1)
 glob = Global()
 
+class Arg:
+    _alloc_nonmovable_ = True
 
-def add_at_end_of_chained_list(node, value):
+
+def add_at_end_of_chained_list(arg):
+    node = arg.anchor
+    value = arg.value
     x = Node(value)
     while node.next:
         node = node.next
@@ -46,14 +52,23 @@
     print "check ok!"
 
 
-def run_me():
-    print "thread starting..."
-    for i in range(glob.LENGTH):
-        add_at_end_of_chained_list(glob.anchor, i)
-        rstm.transaction_boundary()
+def increment_done(arg):
     print "thread done."
     glob.done += 1
 
+def run_me():
+    debug_print("thread starting...")
+    arg = Arg()
+    rstm.descriptor_init()
+    try:
+        for i in range(glob.LENGTH):
+            arg.anchor = glob.anchor
+            arg.value = i
+            rstm.perform_transaction(add_at_end_of_chained_list, Arg, arg)
+        rstm.perform_transaction(increment_done, Arg, arg)
+    finally:
+        rstm.descriptor_done()
+
 
 # __________  Entry point  __________
 


More information about the pypy-commit mailing list