[pypy-svn] r55316 - in pypy/branch/gc+thread/pypy/module/thread: . test
arigo at codespeak.net
arigo at codespeak.net
Tue May 27 20:15:46 CEST 2008
Author: arigo
Date: Tue May 27 20:15:44 2008
New Revision: 55316
Modified:
pypy/branch/gc+thread/pypy/module/thread/gil.py
pypy/branch/gc+thread/pypy/module/thread/ll_thread.py
pypy/branch/gc+thread/pypy/module/thread/os_thread.py
pypy/branch/gc+thread/pypy/module/thread/test/test_ll_thread.py
Log:
Use the special gc-thread operations in the PyPy mixedmodule too.
Modified: pypy/branch/gc+thread/pypy/module/thread/gil.py
==============================================================================
--- pypy/branch/gc+thread/pypy/module/thread/gil.py (original)
+++ pypy/branch/gc+thread/pypy/module/thread/gil.py Tue May 27 20:15:44 2008
@@ -53,6 +53,7 @@
# This is a single external function so that we are sure that nothing
# occurs between the release and the acquire, e.g. no GC operation.
GIL.fused_release_acquire()
+ thread.gc_thread_run()
def getGIL(self):
return self.GIL # XXX temporary hack!
@@ -87,4 +88,5 @@
def after_external_call():
e = get_errno()
spacestate.GIL.acquire(True)
+ thread.gc_thread_run()
set_errno(e)
Modified: pypy/branch/gc+thread/pypy/module/thread/ll_thread.py
==============================================================================
--- pypy/branch/gc+thread/pypy/module/thread/ll_thread.py (original)
+++ pypy/branch/gc+thread/pypy/module/thread/ll_thread.py Tue May 27 20:15:44 2008
@@ -11,6 +11,8 @@
from pypy.annotation import model as annmodel
from pypy.rpython.lltypesystem.lltype import typeOf
from pypy.rlib.debug import ll_assert
+from pypy.rlib.objectmodel import we_are_translated
+from pypy.rpython.lltypesystem.lloperation import llop
from pypy.tool import autopath
from distutils import sysconfig
python_inc = sysconfig.get_python_inc()
@@ -141,3 +143,32 @@
def __del__(self):
lltype.free(self._lock, flavor='raw')
+
+# ____________________________________________________________
+#
+# Thread integration.
+# These are three completely ad-hoc operations at the moment.
+
+def gc_thread_prepare():
+ """To call just before thread.start_new_thread(). This
+ allocates a new shadow stack to be used by the future
+ thread. If memory runs out, this raises a MemoryError
+ (which can be handled by the caller instead of just getting
+ ignored if it was raised in the newly starting thread).
+ """
+ if we_are_translated():
+ llop.gc_thread_prepare(lltype.Void)
+
+def gc_thread_run():
+ """To call whenever the current thread (re-)acquired the GIL.
+ """
+ if we_are_translated():
+ llop.gc_thread_run(lltype.Void)
+
+def gc_thread_die():
+ """To call just before the final GIL release done by a dying
+ thread. After a thread_die(), no more gc operation should
+ occur in this thread.
+ """
+ if we_are_translated():
+ llop.gc_thread_die(lltype.Void)
Modified: pypy/branch/gc+thread/pypy/module/thread/os_thread.py
==============================================================================
--- pypy/branch/gc+thread/pypy/module/thread/os_thread.py (original)
+++ pypy/branch/gc+thread/pypy/module/thread/os_thread.py Tue May 27 20:15:44 2008
@@ -45,7 +45,10 @@
finally:
# clean up space.threadlocals to remove the ExecutionContext
# entry corresponding to the current thread
- space.threadlocals.leave_thread(space)
+ try:
+ space.threadlocals.leave_thread(space)
+ finally:
+ thread.gc_thread_die()
bootstrap = staticmethod(bootstrap)
def acquire(space, w_callable, args):
@@ -108,6 +111,7 @@
bootstrapper.acquire(space, w_callable, args)
try:
try:
+ thread.gc_thread_prepare()
ident = thread.start_new_thread(bootstrapper.bootstrap, ())
except Exception, e:
bootstrapper.release() # normally called by the new thread
Modified: pypy/branch/gc+thread/pypy/module/thread/test/test_ll_thread.py
==============================================================================
--- pypy/branch/gc+thread/pypy/module/thread/test/test_ll_thread.py (original)
+++ pypy/branch/gc+thread/pypy/module/thread/test/test_ll_thread.py Tue May 27 20:15:44 2008
@@ -2,8 +2,6 @@
from pypy.module.thread.ll_thread import *
from pypy.translator.c.test.test_boehm import AbstractGCTestClass
from pypy.rpython.lltypesystem import lltype, rffi
-from pypy.rpython.lltypesystem.lloperation import llop
-from pypy.rlib.objectmodel import we_are_translated
import py
def setup_module(mod):
@@ -125,19 +123,16 @@
def bootstrap():
state.gil.acquire(True)
- if we_are_translated():
- llop.gc_thread_run(lltype.Void)
+ gc_thread_run()
z = state.z
state.z = None
z.run()
- if we_are_translated():
- llop.gc_thread_die(lltype.Void)
+ gc_thread_die()
state.gil.release()
def g(i, j):
state.z = Z(i, j)
- if we_are_translated():
- llop.gc_thread_prepare(lltype.Void)
+ gc_thread_prepare()
start_new_thread(bootstrap, ())
# now wait until the new thread really started and consumed 'z'
willing_to_wait_more = 1000
@@ -147,8 +142,7 @@
state.gil.release()
time.sleep(0.005)
state.gil.acquire(True)
- if we_are_translated():
- llop.gc_thread_run(lltype.Void)
+ gc_thread_run()
def f():
state.gil = allocate_lock_NOAUTO()
@@ -168,8 +162,7 @@
state.gil.release()
time.sleep(0.01)
state.gil.acquire(True)
- if we_are_translated():
- llop.gc_thread_run(lltype.Void)
+ gc_thread_run()
state.gil.release()
time.sleep(0.1)
return len(state.answers)
More information about the Pypy-commit
mailing list