예제 #1
0
 def compareAndSet(self, expected, update):
     with unique_lock(self._lock):
         if self._v == expected:
             self._v = update
             return True
         else:
             return False
예제 #2
0
 def compareAndSet(self, expected, update):
     with unique_lock(self._lock):
         if self._v == expected:
             self._v = update
             return True
         else:
             return False
예제 #3
0
    def getRef(self, ref):
        """
        Returns a value for the desired ref in this transaction. Ensures that a transaction is running, and
        returns *either* the latest in-transaction-value for this ref (is there is one), or the latest committed
        value that was committed before the start of this transaction.

        If there is no committed value for this ref before this transaction began, it records a fault for the ref,
        and triggers a retry
        """
        if not self._info or not self._info.running():
            self._retry("RETRY - Not running in getRef")

        # Return in-transaction-value if we have one
        if ref in self._vals:
            return self._vals[ref]

        # Might raise a retry exception
        with unique_lock(ref._lock):
            if not ref._tvals:
                raise IllegalStateException("Ref in transaction doRef is unbound! ", ref)

            historypoint = ref._tvals
            while True:
                # log("Checking: %s < %s" % (historypoint.point, self._readPoint))
                if historypoint.point < self._readPoint:
                    return historypoint.val

                # Get older history value, if we loop around to the front we're done
                historypoint = historypoint.prev
                if historypoint == ref._tvals:
                    break

        # Could not find an old-enough committed value, fault!
        ref._faults.getAndIncrement()
        self._retry("RETRY - Fault, no new-enough value!")
예제 #4
0
 def getAndIncrement(self):
     with unique_lock(self._lock):
         self._v += 1
         return self._v
예제 #5
0
 def set(self, v):
     with unique_lock(self._lock): self._v = v
예제 #6
0
 def getAndIncrement(self):
     with unique_lock(self._lock):
         self._v += 1
         return self._v
예제 #7
0
 def set(self, v):
     with unique_lock(self._lock):
         self._v = v