[pypy-svn] r16173 - pypy/dist/pypy/interpreter
arigo at codespeak.net
arigo at codespeak.net
Fri Aug 19 19:14:25 CEST 2005
Author: arigo
Date: Fri Aug 19 19:14:21 2005
New Revision: 16173
Modified:
pypy/dist/pypy/interpreter/baseobjspace.py
pypy/dist/pypy/interpreter/executioncontext.py
pypy/dist/pypy/interpreter/miscutils.py
Log:
A change in preparation for thread support (which remains completely
independent from the core): the 'space.threadlocals' object, which contained
the executioncontext, has now a well-defined method-based interface for
reading and setting the executioncontext and for "making a pause" between
bytecodes, for cooperative scheduling.
Thread strategies are implemented by patching 'space.threadlocals' to point to
an instance of a different class, with methods that really provide thread
support. The default 'space.threadlocals' holds just a single
executioncontext, like before. Patching is done in the init method of the
selected thread module.
Modified: pypy/dist/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/dist/pypy/interpreter/baseobjspace.py (original)
+++ pypy/dist/pypy/interpreter/baseobjspace.py Fri Aug 19 19:14:21 2005
@@ -230,17 +230,17 @@
def getexecutioncontext(self):
"Return what we consider to be the active execution context."
- ec = self.threadlocals.executioncontext
+ ec = self.threadlocals.getvalue()
if ec is None:
ec = self.createexecutioncontext()
- self.threadlocals.executioncontext = ec
+ self.threadlocals.setvalue(ec)
return ec
def _freeze_(self):
# Important: the annotator must not see a prebuilt ExecutionContext
# for reasons related to the specialization of the framestack attribute
# so we make sure there is no executioncontext at freeze-time
- self.threadlocals.executioncontext = None
+ self.threadlocals.setvalue(None)
return True
def createexecutioncontext(self):
Modified: pypy/dist/pypy/interpreter/executioncontext.py
==============================================================================
--- pypy/dist/pypy/interpreter/executioncontext.py (original)
+++ pypy/dist/pypy/interpreter/executioncontext.py Fri Aug 19 19:14:21 2005
@@ -20,7 +20,7 @@
self.space.wrap("maximum recursion depth exceeded"))
try:
frame.f_back = self.framestack.top()
- except:
+ except IndexError:
frame.f_back = None
if not frame.hide():
@@ -57,6 +57,7 @@
def bytecode_trace(self, frame):
"Trace function called before each bytecode."
+ self.space.threadlocals.yield_thread()
if self.is_tracing or frame.w_f_trace is None:
return
code = getattr(frame, 'pycode')
Modified: pypy/dist/pypy/interpreter/miscutils.py
==============================================================================
--- pypy/dist/pypy/interpreter/miscutils.py (original)
+++ pypy/dist/pypy/interpreter/miscutils.py Fri Aug 19 19:14:21 2005
@@ -82,9 +82,20 @@
class ThreadLocals:
- """Thread-local storage."""
- # XXX this is not really thread-local at the moment.
- # XXX reconsider how this should be implemented when we add threads.
+ """Pseudo thread-local storage, for 'space.threadlocals'.
+ This is not really thread-local at all; the intention is that the PyPy
+ implementation of the 'thread' module knows how to provide a real
+ implementation for this feature, and patches 'space.threadlocals' when
+ 'thread' is initialized.
+ """
+ _value = None
- def __init__(self):
- self.executioncontext = None
+ def getvalue(self):
+ return self._value
+
+ def setvalue(self, value):
+ self._value = value
+
+ def yield_thread(self):
+ """Called from time to time between the interpretation of bytecodes.
+ Hook for threading models that require it."""
More information about the Pypy-commit
mailing list