org.exist.storage.lock
Class ReentrantReadWriteLock

java.lang.Object
  extended by org.exist.storage.lock.ReentrantReadWriteLock
All Implemented Interfaces:
Lock

public class ReentrantReadWriteLock
extends Object
implements Lock

A lock with the same semantics as builtin Java synchronized locks: Once a thread has a lock, it can re-obtain it any number of times without blocking. The lock is made available to other threads when as many releases as acquires have occurred. The lock has a timeout: a read lock will be released if the timeout is reached.


Field Summary
 int mode_
           
 
Fields inherited from interface org.exist.storage.lock.Lock
NO_LOCK, READ_LOCK, WRITE_LOCK
 
Constructor Summary
ReentrantReadWriteLock(Object id)
           
 
Method Summary
 boolean acquire()
          Acquire a lock for read.
 boolean acquire(int mode)
          Acquire a lock for read or write.
 boolean attempt(int mode)
          Attempt to acquire a lock for read or write.
 String getId()
           
 LockInfo getLockInfo()
          Create a LockInfo entry for the given lock.
 Thread getOwner()
           
 boolean hasLock()
          Check if the lock is currently locked by someone.
 boolean hasLock(Thread owner)
          Check if the specified thread holds either a write or a read lock on the resource.
 long holds()
          Return the number of unreleased acquires performed by the current thread.
 boolean isLockedForRead(Thread owner)
          Check if the specified thread does currently hold a read lock.
 boolean isLockedForWrite()
          Returns true if there are active or pending write locks.
 void release(int mode)
          Release a lock of the specified type.
 void release(int mode, int count)
           
 void wakeUp()
          Wake up waiting threads and recompute dependencies.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mode_

public int mode_
Constructor Detail

ReentrantReadWriteLock

public ReentrantReadWriteLock(Object id)
Method Detail

getId

public String getId()
Specified by:
getId in interface Lock

acquire

public boolean acquire()
                throws LockException
Description copied from interface: Lock
Acquire a lock for read.

Specified by:
acquire in interface Lock
Throws:
LockException

acquire

public boolean acquire(int mode)
                throws LockException
Description copied from interface: Lock
Acquire a lock for read or write. mode is one of Lock.READ_LOCK or Lock.WRITE_LOCK.

Specified by:
acquire in interface Lock
Throws:
LockException

wakeUp

public void wakeUp()
Description copied from interface: Lock
Wake up waiting threads and recompute dependencies. Currently used to rerun deadlock detection.

Specified by:
wakeUp in interface Lock

attempt

public boolean attempt(int mode)
Description copied from interface: Lock
Attempt to acquire a lock for read or write. This method will fail immediately if the lock cannot be acquired.

Specified by:
attempt in interface Lock

isLockedForWrite

public boolean isLockedForWrite()
Description copied from interface: Lock
Returns true if there are active or pending write locks.

Specified by:
isLockedForWrite in interface Lock

isLockedForRead

public boolean isLockedForRead(Thread owner)
Description copied from interface: Lock
Check if the specified thread does currently hold a read lock.

Specified by:
isLockedForRead in interface Lock
Parameters:
owner - the thread to search for
Returns:
true if the thread holds a read lock

hasLock

public boolean hasLock()
Description copied from interface: Lock
Check if the lock is currently locked by someone.

Specified by:
hasLock in interface Lock
Returns:
true if there's an active read or write lock

hasLock

public boolean hasLock(Thread owner)
Description copied from interface: Lock
Check if the specified thread holds either a write or a read lock on the resource.

Specified by:
hasLock in interface Lock
Parameters:
owner - the thread
Returns:
true if owner has a lock

getOwner

public Thread getOwner()

release

public void release(int mode)
Description copied from interface: Lock
Release a lock of the specified type.

Specified by:
release in interface Lock

release

public void release(int mode,
                    int count)
Specified by:
release in interface Lock

holds

public long holds()
Return the number of unreleased acquires performed by the current thread. Returns zero if current thread does not hold lock.


getLockInfo

public LockInfo getLockInfo()
Description copied from interface: Lock
Create a LockInfo entry for the given lock.

Specified by:
getLockInfo in interface Lock
Returns:
the lock info


Copyright (C) Wolfgang Meier. All rights reserved.