[pypy-commit] stmgc c7: re-implement thread switching
Raemi
noreply at buildbot.pypy.org
Tue Jan 14 15:34:33 CET 2014
Author: Remi Meier <remi.meier at gmail.com>
Branch: c7
Changeset: r607:3b6bf19bff12
Date: 2014-01-14 15:34 +0100
http://bitbucket.org/pypy/stmgc/changeset/3b6bf19bff12/
Log: re-implement thread switching
diff --git a/c7/test/support.py b/c7/test/support.py
--- a/c7/test/support.py
+++ b/c7/test/support.py
@@ -102,23 +102,19 @@
def setup_method(self, meth):
lib.stm_setup()
lib.stm_setup_thread()
- self.saved_states = {}
- self.current_proc = "main"
+ lib.stm_setup_thread()
+ lib._stm_restore_local_state(0)
+ self.current_thread = 0
def teardown_method(self, meth):
+ lib._stm_restore_local_state(1)
lib._stm_teardown_thread()
- for saved_state in self.saved_states.values():
- lib._stm_restore_local_state(saved_state)
- lib._stm_teardown_thread()
- del self.saved_states
+ lib._stm_restore_local_state(0)
+ lib._stm_teardown_thread()
lib._stm_teardown()
- def switch(self, process_name):
- self.saved_states[self.current_proc] = lib._stm_save_local_state()
- try:
- target_saved_state = self.saved_states.pop(process_name)
- except KeyError:
- lib.stm_setup_thread()
- else:
- lib._stm_restore_local_state(target_saved_state)
- self.current_proc = process_name
+ def switch(self, thread_num):
+ assert thread_num != self.current_thread
+ lib._stm_restore_local_state(thread_num)
+ self.current_thread = thread_num
+
diff --git a/c7/test/test_basic.py b/c7/test/test_basic.py
--- a/c7/test/test_basic.py
+++ b/c7/test/test_basic.py
@@ -15,11 +15,11 @@
p3 = stm_allocate(16)
assert p3 - p2 == 16
#
- self.switch("sub1")
+ self.switch(1)
p1s = stm_allocate(16)
assert abs(p1s - p3) >= 4000
#
- self.switch("main")
+ self.switch(0)
p4 = stm_allocate(16)
assert p4 - p3 == 16
More information about the pypy-commit
mailing list