[pypy-commit] pypy stm-thread: Tweaks to replace the GIL.
arigo
noreply at buildbot.pypy.org
Mon May 7 14:54:57 CEST 2012
Author: Armin Rigo <arigo at tunes.org>
Branch: stm-thread
Changeset: r54935:db915a95f6ed
Date: 2012-05-07 14:54 +0200
http://bitbucket.org/pypy/pypy/changeset/db915a95f6ed/
Log: Tweaks to replace the GIL.
diff --git a/pypy/module/thread/__init__.py b/pypy/module/thread/__init__.py
--- a/pypy/module/thread/__init__.py
+++ b/pypy/module/thread/__init__.py
@@ -24,10 +24,14 @@
def __init__(self, space, *args):
"NOT_RPYTHON: patches space.threadlocals to use real threadlocals"
- from pypy.module.thread import gil
MixedModule.__init__(self, space, *args)
prev = space.threadlocals.getvalue()
- space.threadlocals = gil.GILThreadLocals()
+ if space.config.translation.stm:
+ from pypy.module.thread import stm
+ space.threadlocals = stm.STMThreadLocals()
+ else:
+ from pypy.module.thread import gil
+ space.threadlocals = gil.GILThreadLocals()
space.threadlocals.initialize(space)
space.threadlocals.setvalue(prev)
diff --git a/pypy/module/thread/gil.py b/pypy/module/thread/gil.py
--- a/pypy/module/thread/gil.py
+++ b/pypy/module/thread/gil.py
@@ -2,6 +2,8 @@
Global Interpreter Lock.
"""
+... do not import me for now ...
+
# This module adds a global lock to an object space.
# If multiple threads try to execute simultaneously in this space,
# all but one will be blocked. The other threads get a chance to run
diff --git a/pypy/module/thread/stm.py b/pypy/module/thread/stm.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/thread/stm.py
@@ -0,0 +1,22 @@
+"""
+Software Transactional Memory emulation of the GIL.
+"""
+
+from pypy.module.thread.threadlocals import OSThreadLocals
+from pypy.rlib import rstm
+from pypy.rlib.objectmodel import invoke_around_extcall
+
+
+class STMThreadLocals(OSThreadLocals):
+
+ def initialize(self, space):
+ pass
+
+ def setup_threads(self, space):
+ invoke_around_extcall(rstm.before_external_call,
+ rstm.after_external_call,
+ rstm.enter_callback_call,
+ rstm.leave_callback_call)
+
+ def reinit_threads(self, space):
+ self.setup_threads(space)
More information about the pypy-commit
mailing list