Example #1
0
 def put(self, value):
     """
     Inserts an item into this queue. The item will then become available on
     all endpoints created from it.
     """
     item = _BroadcastItem(value, stm.TVar())
     self._var.set(item)
     self._var = item.next
Example #2
0
 def __init__(self, initial_values=[]):
     self.var = stm.TVar(ttftree.Empty(ttftree.MEASURE_ITEM_COUNT))
     if initial_values:
         # If initial_values is an instance of Tree, we automatically get
         # O(1) performance here with no effort on our part: extend() is
         # overridden to just concatenate our respective trees in such a
         # case, and concatenation is O(log min(m, n)), which becomes O(1)
         # when one of the trees (our initial empty tree) is empty.
         self.extend(initial_values)
Example #3
0
    def set(self, value):
        if self._ref.get() is not None:
            self._callback_var.set(False)
        self._callback_var = stm.TVar(True)

        def callback_wrapper(v=self._callback_var, c=self._callback):
            if v.get():
                c()

        self._ref = stm.TWeakRef(value, callback_wrapper)
Example #4
0
 def __init__(self, value, callback=None):
     """
     Create a TMutableWeakRef with the specified initial value.
     
     Note that, as Python does not permit weak references to None, an
     initial non-None value must be specified.
     """
     self._callback = callback
     # Set a dummy _callback_var for self.set's sake
     self._callback_var = stm.TVar()
     self.set(value)
Example #5
0
 def __init__(self, initial_values=None):
     self.var = stm.TVar(ttftree.Empty(_DICT_MEASURE))
     if initial_values:
         # Optimize to O(1) if we're cloning another TDict
         if isinstance(initial_values, TDict):
             self.var.set(initial_values.var.get())
         # Initializing from another dict-like object
         elif hasattr(initial_values, "keys"):
             for k in initial_values.keys():
                 self[k] = initial_values[k]
         # Initializing from a sequence of 2-tuples
         else:
             for k, v in initial_values:
                 self[k] = v
Example #6
0
 def replace(self, value):
     """
     Pushes the specified value back onto this endpoint, such that the next
     call to get() will return the specified value.
     
     This is used internally to implement peek() and is_empty: an item is
     retrieved from the endpoint and then immediately pushed back onto the
     endpoint with replace(), thus leaving the endpoint unmodified. It can
     also be used externally as needed.
     
     This can be called multiple times to push multiple items onto an
     endpoint in LIFO order.
     """
     item = _BroadcastItem(value, self._var)
     self._var = stm.TVar(item)
Example #7
0
 def __init__(self):
     """
     Creates a new, empty broadcast queue.
     """
     TObject.__init__(self)
     self._var = stm.TVar(None)
Example #8
0
 def __init__(self, initial_items=set(), backing_type=set):
     self.backing_type = backing_type
     self._var = stm.TVar(backing_type(initial_items))