public String describeWaitList() { StringBuilder sb = new StringBuilder(this + " waits for ["); PrimitiveIntIterator iter = waitList.iterator(); while (iter.hasNext()) { sb.append(iter.next()).append(", "); } sb.append("]"); return sb.toString(); }
private void markAsWaitingFor( ForsetiLockManager.Lock lock, Locks.ResourceType type, long resourceId) { clearWaitList(); lock.copyHolderWaitListsInto(waitList); if (lock.anyHolderIsWaitingFor(myId) && lock.holderWaitListSize() >= waitListSize()) { waitList.clear(); throw new DeadlockDetectedException( this + " can't acquire " + lock + " on " + type + "(" + resourceId + "), because holders of that lock " + "are waiting for " + this + ".\n Wait list:" + lock.describeWaitList()); } }
private void clearWaitList() { waitList.clear(); waitList.put(myId); }
public boolean isWaitingFor(int clientId) { // TODO Similarly to the above, make reading the waitList a volatile load. return clientId != myId && waitList.contains(clientId); }
public void copyWaitListTo(SimpleBitSet other) { other.put(waitList); // TODO It might make sense to somehow put a StoreLoad barrier here, // TODO to expidite the observation of the updated waitList in other clients. }
public int waitListSize() { return waitList.size(); }