Package org.apache.ignite.internal.util
Class OffheapReadWriteLock
- java.lang.Object
-
- org.apache.ignite.internal.util.OffheapReadWriteLock
-
public class OffheapReadWriteLock extends Object
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
Fields Modifier and Type Field Description static intDFLT_OFFHEAP_RWLOCK_SPIN_COUNTstatic StringIGNITE_OFFHEAP_RANDOM_RW_POLICYstatic StringIGNITE_OFFHEAP_RWLOCK_SPIN_COUNTstatic intLOCK_SIZELock size.static intMAX_WAITERSMaximum number of waiting threads, read or write.static intSPIN_CNTTODO benchmark optimal spin count.static intTAG_LOCK_ALWAYSAlways lock tag.static booleanUSE_RANDOM_RW_POLICY
-
Constructor Summary
Constructors Constructor Description OffheapReadWriteLock(int concLvl)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidinit(long lock, int tag)booleanisReadLocked(long lock)booleanisWriteLocked(long lock)booleanreadLock(long lock, int tag)voidreadUnlock(long lock)booleantryWriteLock(long lock, int tag)BooleanupgradeToWriteLock(long lock, int tag)Upgrades a read lock to a write lock.booleanwriteLock(long lock, int tag)voidwriteUnlock(long lock, int tag)
-
-
-
Field Detail
-
DFLT_OFFHEAP_RWLOCK_SPIN_COUNT
public static final int DFLT_OFFHEAP_RWLOCK_SPIN_COUNT
-
IGNITE_OFFHEAP_RWLOCK_SPIN_COUNT
@SystemProperty(value="A number of spin-lock iterations to take before falling back to the blocking approach", type=java.lang.Long.class, defaults="32") public static final String IGNITE_OFFHEAP_RWLOCK_SPIN_COUNT
- See Also:
- Constant Field Values
-
IGNITE_OFFHEAP_RANDOM_RW_POLICY
@SystemProperty(value="The OffheapReadWriteLock flag that switches between signal to writers and signal to random policy", defaults="Default is false that means always signal to writers") public static final String IGNITE_OFFHEAP_RANDOM_RW_POLICY
- See Also:
- Constant Field Values
-
SPIN_CNT
public static final int SPIN_CNT
TODO benchmark optimal spin count.
-
USE_RANDOM_RW_POLICY
public static final boolean USE_RANDOM_RW_POLICY
-
TAG_LOCK_ALWAYS
public static final int TAG_LOCK_ALWAYS
Always lock tag.- See Also:
- Constant Field Values
-
LOCK_SIZE
public static final int LOCK_SIZE
Lock size.- See Also:
- Constant Field Values
-
MAX_WAITERS
public static final int MAX_WAITERS
Maximum number of waiting threads, read or write.- See Also:
- Constant Field Values
-
-
Method Detail
-
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
public Boolean upgradeToWriteLock(long lock, int tag)
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.
-
-