Package org.apache.ignite.internal.util
Class OffheapReadWriteLock
java.lang.Object
org.apache.ignite.internal.util.OffheapReadWriteLock
Lock state structure is as follows:
+----------------+---------------+---------+----------+
| WRITE WAIT CNT | READ WAIT CNT | TAG | LOCK CNT |
+----------------+---------------+---------+----------+
| 2 bytes | 2 bytes | 2 bytes | 2 bytes |
+----------------+---------------+---------+----------+
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intLock size.static final intMaximum number of waiting threads, read or write.static final intTODO benchmark optimal spin count.static final intAlways lock tag.static final boolean -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidinit(long lock, int tag) booleanisReadLocked(long lock) booleanisWriteLocked(long lock) booleanreadLock(long lock, int tag) voidreadUnlock(long lock) booleantryWriteLock(long lock, int tag) upgradeToWriteLock(long lock, int tag) Upgrades a read lock to a write lock.booleanwriteLock(long lock, int tag) voidwriteUnlock(long lock, int tag)
-
Field Details
-
DFLT_OFFHEAP_RWLOCK_SPIN_COUNT
public static final int DFLT_OFFHEAP_RWLOCK_SPIN_COUNT- See Also:
-
#IGNITE_OFFHEAP_RWLOCK_SPIN_COUNT- Constant Field Values
-
SPIN_CNT
public static final int SPIN_CNTTODO benchmark optimal spin count.- See Also:
-
USE_RANDOM_RW_POLICY
public static final boolean USE_RANDOM_RW_POLICY- See Also:
-
TAG_LOCK_ALWAYS
public static final int TAG_LOCK_ALWAYSAlways lock tag.- See Also:
-
LOCK_SIZE
public static final int LOCK_SIZELock size.- See Also:
-
MAX_WAITERS
public static final int MAX_WAITERSMaximum number of waiting threads, read or write.- See Also:
-
-
Constructor Details
-
OffheapReadWriteLock
public OffheapReadWriteLock(int concLvl) - Parameters:
concLvl- Concurrency level, must be a power of two.
-
-
Method Details
-
init
public void init(long lock, int tag) - Parameters:
lock- Lock pointer to initialize.
-
readLock
public boolean readLock(long lock, int tag) - Parameters:
lock- Lock address.
-
readUnlock
public void readUnlock(long lock) - Parameters:
lock- Lock address.
-
tryWriteLock
public boolean tryWriteLock(long lock, int tag) - Parameters:
lock- Lock address.
-
writeLock
public boolean writeLock(long lock, int tag) - Parameters:
lock- Lock address.
-
isWriteLocked
public boolean isWriteLocked(long lock) - Parameters:
lock- Lock to check.- Returns:
Trueif write lock is held by any thread for the given offheap RW lock.
-
isReadLocked
public boolean isReadLocked(long lock) - Parameters:
lock- Lock to check.- Returns:
Trueif at least one read lock is held by any thread for the given offheap RW lock.
-
writeUnlock
public void writeUnlock(long lock, int tag) - Parameters:
lock- Lock address.
-
upgradeToWriteLock
Upgrades a read lock to a write lock. If this thread is the only read-owner of the read lock, this method will atomically upgrade the read lock to the write lock. In this casetruewill be returned. If not, the read lock will be released and write lock will be acquired, leaving a potential gap for other threads to modify a protected resource. In this case this method will returnfalse.After this method has been called, there is no need to call to
readUnlock(long)because read lock will be released in any case.- Parameters:
lock- Lock to upgrade.- Returns:
nullif tag validation failed,trueif successfully traded the read lock to the write lock without leaving a gap. Returnsfalseotherwise, in this case the resource state must be re-validated.
-