Author: Armin Rigo <[email protected]>
Branch: tealet
Changeset: r45391:062824c571a9
Date: 2011-07-06 16:31 +0200
http://bitbucket.org/pypy/pypy/changeset/062824c571a9/
Log: Multithread safety.
diff --git a/pypy/module/tealet/interp_tealet.py
b/pypy/module/tealet/interp_tealet.py
--- a/pypy/module/tealet/interp_tealet.py
+++ b/pypy/module/tealet/interp_tealet.py
@@ -20,6 +20,13 @@
w_exception = space.call_function(w_exception_class, space.wrap(error.msg))
return OperationError(w_exception_class, w_exception)
+def check(space, main, funcname):
+ if main is None:
+ raise TealetError("%s to a non-started-yet tealet" % funcname)
+ assert isinstance(main, W_MainTealet)
+ if main.execution_context is not space.get_execution_context():
+ raise TealetError("%s in a different thread" % funcname)
+
# ____________________________________________________________
def W_Tealet_run(self):
@@ -35,10 +42,12 @@
def W_Tealet_switch(space, w_self):
self = space.interp_w(W_Tealet, w_self)
try:
+ check(space, self.main, "switch()")
self.switch()
except TealetError, e:
raise wrap_error(space, e)
+W_Tealet.main = None
W_Tealet.run = W_Tealet_run
W_Tealet.typedef = TypeDef(
'Tealet',
@@ -53,12 +62,14 @@
r = space.allocate_instance(W_MainTealet, w_subtype)
r.__init__()
r.space = space
+ r.execution_context = space.get_execution_context()
return space.wrap(r)
def W_MainTealet_start(space, w_self, w_tealet):
self = space.interp_w(W_MainTealet, w_self)
tealet = space.interp_w(W_Tealet, w_tealet)
try:
+ check(space, self, "start()")
self.start(tealet)
except TealetError, e:
raise wrap_error(space, e)
diff --git a/pypy/rlib/rtealet.py b/pypy/rlib/rtealet.py
--- a/pypy/rlib/rtealet.py
+++ b/pypy/rlib/rtealet.py
@@ -61,8 +61,6 @@
switcher = Switcher()
def _new(main, starting_tealet):
- #if main.ll_stack_base != _getstackbase():
- # raise TealetError("starting a new tealet in the wrong thread")
switcher.current = main.current
switcher.target = starting_tealet
llmain = main.lltealet
@@ -107,8 +105,6 @@
return llresult
def _switch(target):
- #if target.main.ll_stack_base != _getstackbase():
- # raise TealetError("cannot switch to a tealet in a different thread")
main = target.main
switcher.current = main.current
switcher.target = target
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit