@Test public void downgradeLastEdge() { mLockList.lockRootEdge(LockMode.WRITE); mLockList.downgradeLastEdge(); assertEquals(LockMode.READ, mLockList.getLockMode()); mLockList.lockInode(mRootDir, LockMode.READ); mLockList.lockEdge(mRootDir, mDirA.getName(), LockMode.WRITE); mLockList.downgradeLastEdge(); assertEquals(LockMode.READ, mLockList.getLockMode()); checkOnlyNodesReadLocked(mRootDir); checkOnlyNodesWriteLocked(); checkOnlyIncomingEdgesReadLocked(mRootDir, mDirA); checkOnlyIncomingEdgesWriteLocked(); }
@Override public void downgradeLastEdge() { Preconditions.checkState(!endsInInode(), "Cannot downgrade last edge when lock list %s ends in an inode", this); Preconditions.checkState(!mLocks.isEmpty(), "Cannot downgrade last edge when the lock list is empty"); Preconditions.checkState(endsInWriteLock(), "Cannot downgrade last edge when lock list %s is not write locked", this); if (!endsInMultipleWriteLocks()) { Edge lastEdge = lastEdge(); RWLockResource newLock = mInodeLockManager.lockEdge(lastEdge, LockMode.READ, mUseTryLock); removeLastLock(); addEdgeLock(lastEdge, LockMode.READ, newLock); } }
SimpleInodeLockList implements InodeLockList { @Override public void downgradeLastEdge() { Preconditions.checkState(!endsInInode(), "Cannot downgrade last edge when lock list %s ends in an inode", this); Preconditions.checkState(!mLocks.isEmpty(), "Cannot downgrade last edge when the lock list is empty"); Preconditions.checkState(endsInWriteLock(), "Cannot downgrade last edge when lock list %s is not write locked", this); if (!endsInMultipleWriteLocks()) { Edge lastEdge = lastEdge(); RWLockResource newLock = mInodeLockManager.lockEdge(lastEdge, LockMode.READ, mUseTryLock); removeLastLock(); addEdgeLock(lastEdge, LockMode.READ, newLock); } } }
SimpleInodeLockList implements InodeLockList { @Override public void downgradeLastEdge() { Preconditions.checkState(!endsInInode(), "Cannot downgrade last edge when lock list %s ends in an inode", this); Preconditions.checkState(!mLocks.isEmpty(), "Cannot downgrade last edge when the lock list is empty"); Preconditions.checkState(endsInWriteLock(), "Cannot downgrade last edge when lock list %s is not write locked", this); if (!endsInMultipleWriteLocks()) { Edge lastEdge = lastEdge(); RWLockResource newLock = mInodeLockManager.lockEdge(lastEdge, LockMode.READ, mUseTryLock); removeLastLock(); addEdgeLock(lastEdge, LockMode.READ, newLock); } } SimpleInodeLockList(InodeLockManager inodeLockManager, boolean useTryLock); }
SimpleInodeLockList implements InodeLockList { @Override public void downgradeLastEdge() { Preconditions.checkState(!endsInInode(), "Cannot downgrade last edge when lock list %s ends in an inode", this); Preconditions.checkState(!mLocks.isEmpty(), "Cannot downgrade last edge when the lock list is empty"); Preconditions.checkState(endsInWriteLock(), "Cannot downgrade last edge when lock list %s is not write locked", this); if (!endsInMultipleWriteLocks()) { Edge lastEdge = lastEdge(); RWLockResource newLock = mInodeLockManager.lockEdge(lastEdge, LockMode.READ, mUseTryLock); removeLastLock(); addEdgeLock(lastEdge, LockMode.READ, newLock); } } SimpleInodeLockList(InodeLockManager inodeLockManager, boolean useTryLock); @Override void lockInode(Inode inode, LockMode mode); @Override void lockEdge(Inode lastInode, String childName, LockMode mode); @Override void lockRootEdge(LockMode mode); @Override void pushWriteLockedEdge(Inode inode, String childName); @Override void unlockLastInode(); @Override void unlockLastEdge(); @Override void downgradeToReadLocks(); @Override void downgradeLastEdge(); @Override LockMode getLockMode(); @Override List<Inode> getLockedInodes(); @Override Inode get(int index); @Override int numInodes(); @Override boolean isEmpty(); @Override InodeLockManager getInodeLockManager(); @Override boolean endsInInode(); @Override String toString(); @Override void close(); }
SimpleInodeLockList implements InodeLockList { @Override public void downgradeLastEdge() { Preconditions.checkState(!endsInInode(), "Cannot downgrade last edge when lock list %s ends in an inode", this); Preconditions.checkState(!mLocks.isEmpty(), "Cannot downgrade last edge when the lock list is empty"); Preconditions.checkState(endsInWriteLock(), "Cannot downgrade last edge when lock list %s is not write locked", this); if (!endsInMultipleWriteLocks()) { Edge lastEdge = lastEdge(); RWLockResource newLock = mInodeLockManager.lockEdge(lastEdge, LockMode.READ, mUseTryLock); removeLastLock(); addEdgeLock(lastEdge, LockMode.READ, newLock); } } SimpleInodeLockList(InodeLockManager inodeLockManager, boolean useTryLock); @Override void lockInode(Inode inode, LockMode mode); @Override void lockEdge(Inode lastInode, String childName, LockMode mode); @Override void lockRootEdge(LockMode mode); @Override void pushWriteLockedEdge(Inode inode, String childName); @Override void unlockLastInode(); @Override void unlockLastEdge(); @Override void downgradeToReadLocks(); @Override void downgradeLastEdge(); @Override LockMode getLockMode(); @Override List<Inode> getLockedInodes(); @Override Inode get(int index); @Override int numInodes(); @Override boolean isEmpty(); @Override InodeLockManager getInodeLockManager(); @Override boolean endsInInode(); @Override String toString(); @Override void close();  }