viff

changeset 1251:2bbab8b5597f

Centralize the program counter changes.
author Marcel Keller <mkeller@cs.au.dk>
date Mon, 28 Sep 2009 15:59:57 +0200
parents 77f74e53f796
children c8e3e05b8be9
files viff/active.py viff/passive.py viff/runtime.py
diffstat 3 files changed, 16 insertions(+), 4 deletions(-) [+]
line diff
     1.1 --- a/viff/active.py	Sat Sep 19 15:34:01 2009 +0200
     1.2 +++ b/viff/active.py	Mon Sep 28 15:59:57 2009 +0200
     1.3 @@ -47,7 +47,7 @@
     1.4          Principles of Distributed Computing, 1984, pages 154-162.
     1.5          """
     1.6          # We need a unique program counter for each call.
     1.7 -        self.program_counter[-1] += 1
     1.8 +        self.increment_pc()
     1.9  
    1.10          result = Deferred()
    1.11          pc = tuple(self.program_counter)
     2.1 --- a/viff/passive.py	Sat Sep 19 15:34:01 2009 +0200
     2.2 +++ b/viff/passive.py	Mon Sep 28 15:59:57 2009 +0200
     2.3 @@ -250,7 +250,7 @@
     2.4          starting program counter. This ensures that consequetive calls
     2.5          to PRSS-related methods will use unique program counters.
     2.6          """
     2.7 -        self.program_counter[-1] += 1
     2.8 +        self.increment_pc()
     2.9          return tuple(self.program_counter)
    2.10  
    2.11      def prss_share(self, inputters, field, element=None):
     3.1 --- a/viff/runtime.py	Sat Sep 19 15:34:01 2009 +0200
     3.2 +++ b/viff/runtime.py	Mon Sep 28 15:59:57 2009 +0200
     3.3 @@ -604,6 +604,18 @@
     3.4          dl = DeferredList(vars)
     3.5          self.schedule_callback(dl, lambda _: self.shutdown())
     3.6  
     3.7 +    def increment_pc(self):
     3.8 +        """Increment the program counter."""
     3.9 +        self.program_counter[-1] += 1
    3.10 +
    3.11 +    def fork_pc(self):
    3.12 +        """Fork the program counter."""
    3.13 +        self.program_counter.append(0)
    3.14 +
    3.15 +    def unfork_pc(self):
    3.16 +        """Leave a fork of the program counter."""
    3.17 +        self.program_counter.pop()
    3.18 +
    3.19      def schedule_callback(self, deferred, func, *args, **kwargs):
    3.20          """Schedule a callback on a deferred with the correct program
    3.21          counter.
    3.22 @@ -617,9 +629,8 @@
    3.23          Any extra arguments are passed to the callback as with
    3.24          :meth:`addCallback`.
    3.25          """
    3.26 -        self.program_counter[-1] += 1
    3.27 +        self.increment_pc()
    3.28          saved_pc = self.program_counter[:]
    3.29 -        saved_pc.append(0)
    3.30  
    3.31          @wrapper(func)
    3.32          def callback_wrapper(*args, **kwargs):
    3.33 @@ -627,6 +638,7 @@
    3.34              try:
    3.35                  current_pc = self.program_counter[:]
    3.36                  self.program_counter[:] = saved_pc
    3.37 +                self.fork_pc()
    3.38                  return func(*args, **kwargs)
    3.39              finally:
    3.40                  self.program_counter[:] = current_pc