[pypy-svn] r23257 - in pypy/dist/pypy: module/thread module/thread/rpython translator/c translator/c/src translator/goal

pedronis at codespeak.net pedronis at codespeak.net
Sun Feb 12 15:26:29 CET 2006


Author: pedronis
Date: Sun Feb 12 15:26:23 2006
New Revision: 23257

Modified:
   pypy/dist/pypy/module/thread/gil.py
   pypy/dist/pypy/module/thread/rpython/exttable.py
   pypy/dist/pypy/module/thread/rpython/ll_thread.py
   pypy/dist/pypy/translator/c/extfunc.py
   pypy/dist/pypy/translator/c/src/ll_thread.h
   pypy/dist/pypy/translator/goal/ann_override.py
Log:
fix GIL threading: avoid a RPyExceptionOccured between releasing and re-acquiring the GIL, this is not thread-safe!

Use at translation a fused release-acquire, stop-gap solution...
we need to rethink RPython exception handling thread-safety.



Modified: pypy/dist/pypy/module/thread/gil.py
==============================================================================
--- pypy/dist/pypy/module/thread/gil.py	(original)
+++ pypy/dist/pypy/module/thread/gil.py	Sun Feb 12 15:26:23 2006
@@ -35,6 +35,7 @@
         GIL.release()
         # Other threads can run here
         GIL.acquire(True)
+    yield_thread._annspecialcase_ = 'specialize:yield_thread'
 
     def getGIL(self):
         return self.GIL    # XXX temporary hack!

Modified: pypy/dist/pypy/module/thread/rpython/exttable.py
==============================================================================
--- pypy/dist/pypy/module/thread/rpython/exttable.py	(original)
+++ pypy/dist/pypy/module/thread/rpython/exttable.py	Sun Feb 12 15:26:23 2006
@@ -14,6 +14,9 @@
                            "ThreadLock",
                            acquire = (bool,       '%s/acquire_lock' % module),
                            release = (type(None), '%s/release_lock' % module),
+                           # XXX special case for releasing and reaquiring the GIL
+                           # withouth race condtions on exception handling
+                           fused_release_acquire = (type(None), '%s/fused_release_acquire_lock' % module),
                            )
 
 # ____________________________________________________________

Modified: pypy/dist/pypy/module/thread/rpython/ll_thread.py
==============================================================================
--- pypy/dist/pypy/module/thread/rpython/ll_thread.py	(original)
+++ pypy/dist/pypy/module/thread/rpython/ll_thread.py	Sun Feb 12 15:26:23 2006
@@ -47,6 +47,12 @@
     lock.release()
 ll_releaselock.suggested_primitive = True
 
+def ll_fused_releaseacquirelock(opaqueptr):
+    lock = from_opaque_object(opaqueptr)
+    lock.release()
+    lock.acquire(True)
+ll_fused_releaseacquirelock.suggested_primitive = True
+
 def ll_thread_allocate_lock():
     lockcontainer = malloc(LOCKCONTAINERTYPE)
     ll_newlock(lockcontainer.obj)
@@ -57,3 +63,6 @@
 
 def ll_thread_release_lock(lockcontainer):
     ll_releaselock(lockcontainer.obj)
+
+def ll_thread_fused_release_acquire_lock(lockcontainer):
+    ll_fused_releaseacquirelock(lockcontainer.obj)

Modified: pypy/dist/pypy/translator/c/extfunc.py
==============================================================================
--- pypy/dist/pypy/translator/c/extfunc.py	(original)
+++ pypy/dist/pypy/translator/c/extfunc.py	Sun Feb 12 15:26:23 2006
@@ -48,9 +48,10 @@
         'LL_strtod_parts_to_float',
     ll_strtod.ll_strtod_formatd:
         'LL_strtod_formatd',
-    ll_thread.ll_newlock:          'LL_thread_newlock',
-    ll_thread.ll_acquirelock:      'LL_thread_acquirelock',
-    ll_thread.ll_releaselock:      'LL_thread_releaselock',
+    ll_thread.ll_newlock:            'LL_thread_newlock',
+    ll_thread.ll_acquirelock:        'LL_thread_acquirelock',
+    ll_thread.ll_releaselock:        'LL_thread_releaselock',
+    ll_thread.ll_fused_releaseacquirelock: 'LL_thread_fused_releaseacquirelock',
     ll_thread.ll_thread_start:     'LL_thread_start',
     ll_thread.ll_thread_get_ident: 'LL_thread_get_ident',
     ll_stackless.ll_stackless_switch:             'LL_stackless_switch',

Modified: pypy/dist/pypy/translator/c/src/ll_thread.h
==============================================================================
--- pypy/dist/pypy/translator/c/src/ll_thread.h	(original)
+++ pypy/dist/pypy/translator/c/src/ll_thread.h	Sun Feb 12 15:26:23 2006
@@ -23,6 +23,7 @@
 void LL_thread_newlock(struct RPyOpaque_ThreadLock *lock);
 int LL_thread_acquirelock(struct RPyOpaque_ThreadLock *lock, int waitflag);
 void LL_thread_releaselock(struct RPyOpaque_ThreadLock *lock);
+void LL_thread_fused_releaseacquirelock(struct RPyOpaque_ThreadLock *lock);
 long LL_thread_start(void *func, void *arg);
 long LL_thread_get_ident(void);
 
@@ -57,6 +58,11 @@
 	}
 }
 
+void LL_thread_fused_releaseacquirelock(struct RPyOpaque_ThreadLock *lock) {
+        LL_thread_releaselock(lock);
+        LL_thread_acquirelock(lock, 1);
+}
+
 long LL_thread_start(void *func, void *arg)
 {
 	/* XXX func() should not raise exceptions */

Modified: pypy/dist/pypy/translator/goal/ann_override.py
==============================================================================
--- pypy/dist/pypy/translator/goal/ann_override.py	(original)
+++ pypy/dist/pypy/translator/goal/ann_override.py	Sun Feb 12 15:26:23 2006
@@ -31,6 +31,14 @@
     #    clsdef = getbookkeeper().getuniqueclassdef(pycode.PyCode)
     #    return annmodel.SomeInstance(clsdef)    
 
+    def specialize__yield_thread(pol, funcdesc, args_s):
+        def yield_thread(self):
+            GIL = self.GIL
+            GIL.fused_release_acquire()
+        def builder(translator, func):
+            return translator.buildflowgraph(yield_thread)
+        return funcdesc.cachedgraph(None, builder=builder)
+     
     def specialize__wrap(pol,  funcdesc, args_s):
         from pypy.interpreter.baseobjspace import Wrappable
         from pypy.annotation.classdef import ClassDef



More information about the Pypy-commit mailing list