Author: Armin Rigo <[email protected]>
Branch: stmgc-c7
Changeset: r75488:ebe1ffb23101
Date: 2015-01-22 17:32 +0100
http://bitbucket.org/pypy/pypy/changeset/ebe1ffb23101/

Log:    Trying to parallelize the rtyper

diff --git a/lib_pypy/transaction.py b/lib_pypy/transaction.py
--- a/lib_pypy/transaction.py
+++ b/lib_pypy/transaction.py
@@ -37,10 +37,10 @@
     signals_enabled = _SignalsEnabled()
 
 try:
-    from __pypy__.thread import last_abort_info
+    from __pypy__.thread import hint_commit_soon
 except ImportError:
     # Not a STM-enabled PyPy.
-    def last_abort_info():
+    def hint_commit_soon():
         return None
 
 
@@ -221,21 +221,17 @@
                     self.lock_if_released_then_finished.release()
                 raise _Done
 
-    @staticmethod
+    @staticmethod                             
     def _do_it((f, args, kwds), got_exception):
         # this is a staticmethod in order to make sure that we don't
         # accidentally use 'self' in the atomic block.
-        try:
-            while True:
-                with signals_enabled:
-                    with atomic:
-                        info = last_abort_info()
-                        if info is None:
-                            if not got_exception:
-                                f(*args, **kwds)
-                            # else return early if already an exc to reraise
-                            return
-                report_abort_info(info)
+        try:                                  
+            hint_commit_soon()
+            with signals_enabled:
+                with atomic:
+                    if not got_exception:
+                        f(*args, **kwds)
+            hint_commit_soon()
         except:
             got_exception[:] = sys.exc_info()
 
@@ -253,7 +249,7 @@
 _thread_local = _ThreadLocal()
 
 
-def report_abort_info(info):
+def XXXreport_abort_info(info):
     header = info[0]
     f = cStringIO.StringIO()
     if len(info) > 1:
@@ -279,3 +275,27 @@
         header[1], 'atom '*header[3], 'inev '*(header[4]>1),
         header[5], header[6])
     sys.stderr.write(f.getvalue())
+
+
+class threadlocalproperty(object):
+    def __init__(self, *default):
+        self.tl_default = default
+        self.tl_name = intern(str(id(self)))
+
+    def tl_get(self, obj):
+        try:
+            return obj._threadlocalproperties
+        except AttributeError:
+            return obj.__dict__.setdefault('_threadlocalproperties',
+                                           thread._local())
+
+    def __get__(self, obj, cls=None):
+        if obj is None:
+            return self
+        return getattr(self.tl_get(obj), self.tl_name, *self.tl_default)
+
+    def __set__(self, obj, value):
+        setattr(self.tl_get(obj), self.tl_name, value)
+
+    def __delete__(self, obj):
+        delattr(self.tl_get(obj), self.tl_name)
diff --git a/rpython/annotator/annrpython.py b/rpython/annotator/annrpython.py
--- a/rpython/annotator/annrpython.py
+++ b/rpython/annotator/annrpython.py
@@ -76,7 +76,7 @@
         args_s = [self.typeannotation(t) for t in input_arg_types]
 
         # XXX hack
-        annmodel.TLS.check_str_without_nul = (
+        annmodel.STATE.check_str_without_nul = (
             self.translator.config.translation.check_str_without_nul)
 
         flowgraph, inputcells = self.get_call_parameters(function, args_s, 
policy)
@@ -112,7 +112,7 @@
             from rpython.annotator.policy import AnnotatorPolicy
             policy = AnnotatorPolicy()
             # XXX hack
-            annmodel.TLS.check_str_without_nul = (
+            annmodel.STATE.check_str_without_nul = (
                 self.translator.config.translation.check_str_without_nul)
         graph, inputcells = self.get_call_parameters(function, args_s, policy)
         self.build_graph_types(graph, inputcells, complete_now=False)
diff --git a/rpython/annotator/bookkeeper.py b/rpython/annotator/bookkeeper.py
--- a/rpython/annotator/bookkeeper.py
+++ b/rpython/annotator/bookkeeper.py
@@ -40,6 +40,13 @@
 
     Currently used for factories and user-defined classes."""
 
+    try:
+        from transaction import threadlocalproperty
+    except ImportError:
+        pass
+    else:
+        position_key = threadlocalproperty()
+
     def __setstate__(self, dic):
         self.__dict__.update(dic) # normal action
         delayed_imports()
diff --git a/rpython/annotator/model.py b/rpython/annotator/model.py
--- a/rpython/annotator/model.py
+++ b/rpython/annotator/model.py
@@ -43,7 +43,16 @@
     # A global attribute :-(  Patch it with 'True' to enable checking of
     # the no_nul attribute...
     check_str_without_nul = False
-TLS = State()
+STATE = State()
+
+try:
+    import thread
+    TLS = thread._local()
+except ImportError:
+    class Tls(object):
+        pass
+    TLS = Tls()
+
 
 class SomeObject(object):
     """The set of all objects.  Each instance stands
@@ -243,7 +252,7 @@
             return False
         d1 = self.__dict__
         d2 = other.__dict__
-        if not TLS.check_str_without_nul:
+        if not STATE.check_str_without_nul:
             d1 = d1.copy()
             d1['no_nul'] = 0
             d2 = d2.copy()
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to