com.sleepycat.je.latch
Class SharedLatch

java.lang.Object
  extended by java.util.concurrent.locks.ReentrantReadWriteLock
      extended by com.sleepycat.je.latch.SharedLatch
All Implemented Interfaces:
java.io.Serializable, java.util.concurrent.locks.ReadWriteLock

public class SharedLatch
extends java.util.concurrent.locks.ReentrantReadWriteLock

Simple thread-based non-transactional reader-writer/shared-exclusive latch. Latches provide simple exclusive or shared transient locks on objects. Latches are expected to be held for short, defined periods of time. No deadlock detection is provided so it is the caller's responsibility to sequence latch acquisition in an ordered fashion to avoid deadlocks.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.concurrent.locks.ReentrantReadWriteLock
java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock, java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock
 
Constructor Summary
SharedLatch(java.lang.String name)
           
 
Method Summary
 void acquireExclusive()
          Acquire a latch for exclusive/write access.
 boolean acquireExclusiveNoWait()
          Probe a latch for exclusive access, but don't block if it's not available.
 void acquireShared()
          Acquire a latch for shared/read access.
 boolean isOwner()
          Return true if this thread is an owner, reader, or write.
 void release()
          Release an exclusive or shared latch.
 void releaseIfOwner()
          Release the latch.
 void setExclusiveOnly(boolean exclusiveOnly)
          Indicate whether this latch can only be set exclusively (not shared).
 void setName(java.lang.String name)
          Set the latch name, used for latches in objects instantiated from the log.
 boolean setNoteLatch(boolean noteLatch)
          Indicate whether this latch should be tracked in the debugging LatchSupport.latchTable.
 
Methods inherited from class java.util.concurrent.locks.ReentrantReadWriteLock
getOwner, getQueuedReaderThreads, getQueuedThreads, getQueuedWriterThreads, getQueueLength, getReadHoldCount, getReadLockCount, getWaitingThreads, getWaitQueueLength, getWriteHoldCount, hasQueuedThread, hasQueuedThreads, hasWaiters, isFair, isWriteLocked, isWriteLockedByCurrentThread, readLock, toString, writeLock
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SharedLatch

public SharedLatch(java.lang.String name)
Method Detail

setName

public void setName(java.lang.String name)
Set the latch name, used for latches in objects instantiated from the log.


setNoteLatch

public boolean setNoteLatch(boolean noteLatch)
Indicate whether this latch should be tracked in the debugging LatchSupport.latchTable. Always return true so this can be called under an assert.


setExclusiveOnly

public void setExclusiveOnly(boolean exclusiveOnly)
Indicate whether this latch can only be set exclusively (not shared). Used for BIN latches that are Shared, but should only be latched exclusively.


acquireExclusive

public void acquireExclusive()
                      throws DatabaseException
Acquire a latch for exclusive/write access. If the thread already holds the latch for shared access, it cannot be upgraded and LatchException will be thrown. Wait for the latch if some other thread is holding it. If there are threads waiting for access, they will be granted the latch on a FIFO basis if fair latches are enabled. When the method returns, the latch is held for exclusive access.

Throws:
LatchException - if the latch is already held by the current thread for shared access.
DatabaseException

acquireExclusiveNoWait

public boolean acquireExclusiveNoWait()
                               throws DatabaseException
Probe a latch for exclusive access, but don't block if it's not available.

Returns:
true if the latch was acquired, false if it is not available.
Throws:
LatchException - if the latch is already held by the calling thread.
DatabaseException

acquireShared

public void acquireShared()
                   throws DatabaseException
Acquire a latch for shared/read access. Nesting is allowed, that is, the latch may be acquired more than once by the same thread.

Throws:
RunRecoveryException - if an InterruptedException exception occurs.
DatabaseException

release

public void release()
             throws LatchNotHeldException
Release an exclusive or shared latch. If there are other thread(s) waiting for the latch, they are woken up and granted the latch.

Throws:
LatchNotHeldException

releaseIfOwner

public void releaseIfOwner()
                    throws LatchNotHeldException
Release the latch. If there are other thread(s) waiting for the latch, one is woken up and granted the latch. If the latch was not owned by the caller, just return.

Throws:
LatchNotHeldException

isOwner

public boolean isOwner()
Return true if this thread is an owner, reader, or write.