/rev/2bbab8b5597f
changeset: 1251:2bbab8b5597f
user: Marcel Keller <[email protected]>
date: Mon Sep 28 15:59:57 2009 +0200
summary: Centralize the program counter changes.
diffstat:
viff/active.py | 2 +-
viff/passive.py | 2 +-
viff/runtime.py | 16 ++++++++++++++--
3 files changed, 16 insertions(+), 4 deletions(-)
diffs (65 lines):
diff -r 77f74e53f796 -r 2bbab8b5597f viff/active.py
--- a/viff/active.py Sat Sep 19 15:34:01 2009 +0200
+++ b/viff/active.py Mon Sep 28 15:59:57 2009 +0200
@@ -47,7 +47,7 @@
Principles of Distributed Computing, 1984, pages 154-162.
"""
# We need a unique program counter for each call.
- self.program_counter[-1] += 1
+ self.increment_pc()
result = Deferred()
pc = tuple(self.program_counter)
diff -r 77f74e53f796 -r 2bbab8b5597f viff/passive.py
--- a/viff/passive.py Sat Sep 19 15:34:01 2009 +0200
+++ b/viff/passive.py Mon Sep 28 15:59:57 2009 +0200
@@ -250,7 +250,7 @@
starting program counter. This ensures that consequetive calls
to PRSS-related methods will use unique program counters.
"""
- self.program_counter[-1] += 1
+ self.increment_pc()
return tuple(self.program_counter)
def prss_share(self, inputters, field, element=None):
diff -r 77f74e53f796 -r 2bbab8b5597f viff/runtime.py
--- a/viff/runtime.py Sat Sep 19 15:34:01 2009 +0200
+++ b/viff/runtime.py Mon Sep 28 15:59:57 2009 +0200
@@ -604,6 +604,18 @@
dl = DeferredList(vars)
self.schedule_callback(dl, lambda _: self.shutdown())
+ def increment_pc(self):
+ """Increment the program counter."""
+ self.program_counter[-1] += 1
+
+ def fork_pc(self):
+ """Fork the program counter."""
+ self.program_counter.append(0)
+
+ def unfork_pc(self):
+ """Leave a fork of the program counter."""
+ self.program_counter.pop()
+
def schedule_callback(self, deferred, func, *args, **kwargs):
"""Schedule a callback on a deferred with the correct program
counter.
@@ -617,9 +629,8 @@
Any extra arguments are passed to the callback as with
:meth:`addCallback`.
"""
- self.program_counter[-1] += 1
+ self.increment_pc()
saved_pc = self.program_counter[:]
- saved_pc.append(0)
@wrapper(func)
def callback_wrapper(*args, **kwargs):
@@ -627,6 +638,7 @@
try:
current_pc = self.program_counter[:]
self.program_counter[:] = saved_pc
+ self.fork_pc()
return func(*args, **kwargs)
finally:
self.program_counter[:] = current_pc
_______________________________________________
viff-commits mailing list
[email protected]
http://lists.viff.dk/listinfo.cgi/viff-commits-viff.dk