public class OffheapReadWriteLock extends Object
+----------------+---------------+---------+----------+
| WRITE WAIT CNT | READ WAIT CNT | TAG | LOCK CNT |
+----------------+---------------+---------+----------+
| 2 bytes | 2 bytes | 2 bytes | 2 bytes |
+----------------+---------------+---------+----------+
| Modifier and Type | Field and Description |
|---|---|
static int |
DFLT_OFFHEAP_RWLOCK_SPIN_COUNT |
static String |
IGNITE_OFFHEAP_RANDOM_RW_POLICY |
static String |
IGNITE_OFFHEAP_RWLOCK_SPIN_COUNT |
static int |
LOCK_SIZE
Lock size.
|
static int |
MAX_WAITERS
Maximum number of waiting threads, read or write.
|
static int |
SPIN_CNT
TODO benchmark optimal spin count.
|
static int |
TAG_LOCK_ALWAYS
Always lock tag.
|
static boolean |
USE_RANDOM_RW_POLICY |
| Constructor and Description |
|---|
OffheapReadWriteLock(int concLvl) |
| Modifier and Type | Method and Description |
|---|---|
void |
init(long lock,
int tag) |
boolean |
isReadLocked(long lock) |
boolean |
isWriteLocked(long lock) |
boolean |
readLock(long lock,
int tag) |
void |
readUnlock(long lock) |
boolean |
tryWriteLock(long lock,
int tag) |
Boolean |
upgradeToWriteLock(long lock,
int tag)
Upgrades a read lock to a write lock.
|
boolean |
writeLock(long lock,
int tag) |
void |
writeUnlock(long lock,
int tag) |
public static final int DFLT_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
@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
public static final int SPIN_CNT
public static final boolean USE_RANDOM_RW_POLICY
public static final int TAG_LOCK_ALWAYS
public static final int LOCK_SIZE
public static final int MAX_WAITERS
public OffheapReadWriteLock(int concLvl)
concLvl - Concurrency level, must be a power of two.public void init(long lock,
int tag)
lock - Lock pointer to initialize.public boolean readLock(long lock,
int tag)
lock - Lock address.public void readUnlock(long lock)
lock - Lock address.public boolean tryWriteLock(long lock,
int tag)
lock - Lock address.public boolean writeLock(long lock,
int tag)
lock - Lock address.public boolean isWriteLocked(long lock)
lock - Lock to check.True if write lock is held by any thread for the given offheap RW lock.public boolean isReadLocked(long lock)
lock - Lock to check.True if at least one read lock is held by any thread for the given offheap RW lock.public void writeUnlock(long lock,
int tag)
lock - Lock address.public Boolean upgradeToWriteLock(long lock, int tag)
true
will 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 return
false.
After this method has been called, there is no need to call to readUnlock(long) because
read lock will be released in any case.
lock - Lock to upgrade.null if tag validation failed, true if successfully traded the read lock to
the write lock without leaving a gap. Returns false otherwise, in this case the resource
state must be re-validated.
Follow @ApacheIgnite
Ignite Database and Caching Platform : ver. 2.10.0 Release Date : March 10 2021