Ignore:
Timestamp:
Feb 27, 2010 1:20:56 PM (14 years ago)
Author:
Ted Faber <faber@…>
Branches:
axis_example, compt_changes, info-ops, master, version-3.01, version-3.02
Children:
f017447
Parents:
7dc855c
Message:

Documentation and remove the redundant, unused key attribute from the synch_value

File:
1 edited

Legend:

Unmodified
Added
Removed
  • fedd/federation/synch_store.py

    r7dc855c r5e3d889  
    1010    deadlock threads waiting for the assignment.
    1111    """
     12
     13    # Thrown if a key is assigned more than once
    1214    class CollisionError(Exception): pass
     15
     16    # Thrown if a non-existant key is deleted
    1317    class BadDeletionError(Exception): pass
    1418
     19    # A value in the dict.  Each has its own condition (and lock) for threads
     20    # to wait on.
    1521    class synch_value:
    16         def __init__(self, key, value=None):
    17             self.key = key
     22        # The synch_value constructor.
     23        def __init__(self, value=None):
    1824            self.value = value
    1925            self.condition = Condition()
    2026
     27        # Debugging representation
    2128        def __str__(self):
    22             return "key %s value %s cond %s" % \
    23                 (self.key, self.value, self.condition)
     29            return "value %s cond %s" % (self.value, self.condition)
    2430
     31    # The synch_store constructor.  Note that the store has its own lock for
     32    # serializing additions to the dict.
    2533    def __init__(self):
    2634        self.main_lock = Lock()
    2735        self.values = { }
    2836
     37    # Set the value in the dict.  If threads are waiting, wake them.
    2938    def set_value(self, key, value):
    3039        self.main_lock.acquire()
     
    4150                raise synch_store.CollisionError("%s already set" % key)
    4251        else:
    43             self.values[key] = synch_store.synch_value(key, value)
     52            self.values[key] = synch_store.synch_value(value)
    4453            self.main_lock.release()
    4554
     55    # Ask for the value.  If wait is true, wait until the key is set, if it is
     56    # not already.  If wait is false, poll.
    4657    def get_value(self, key, wait=True):
    4758        self.main_lock.acquire()
    4859        if not self.values.has_key(key):
    49             self.values[key] = synch_store.synch_value(key)
     60            self.values[key] = synch_store.synch_value()
    5061        v = self.values[key]
    5162        v.condition.acquire()
     
    5970        return rv
    6071
     72    # Remove the key from the shared store.  If the key is not present or has
     73    # never been set, fail.  Otherwise, wake any waiting threads (there
     74    # shouldn't be any) and remove the value and key from the store.
    6175    def del_value(self, key):
    6276        self.main_lock.acquire()
     
    7589            raise synch_store.BadDeletionError("%s does not exist yet" % key)
    7690
     91    # A debugging representation
    7792    def __str__(self):
    7893        rv = ""
     
    8095        for k, v in self.values.items():
    8196            self.values[k].condition.acquire()
    82             rv += "%s: %s" % ( k, str(self.values[k]))
     97            rv += "%s: %s\n" % ( k, str(self.values[k]))
    8398            self.values[k].condition.release()
    8499        self.main_lock.release()
Note: See TracChangeset for help on using the changeset viewer.