Package io.tlf.jme.jfx.lock
Class AtomicReadWriteLock
- java.lang.Object
-
- io.tlf.jme.jfx.lock.AtomicReadWriteLock
-
- All Implemented Interfaces:
AsyncReadSyncWriteLock,java.util.concurrent.locks.Lock
- Direct Known Subclasses:
FinalAtomicReadWriteLock
public class AtomicReadWriteLock extends java.lang.Object implements AsyncReadSyncWriteLock, java.util.concurrent.locks.Lock
The implementation of theAsyncReadSyncWriteLockusing the severalAtomicIntegerwithout supporting reentrant calls.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.concurrent.atomic.AtomicIntegerreadCountThe count of readers.protected intsinkThe field for consuming CPU.protected java.util.concurrent.atomic.AtomicIntegerwriteCountThe count of writers.protected java.util.concurrent.atomic.AtomicIntegerwriteStatusThe status of write lock.
-
Constructor Summary
Constructors Constructor Description AtomicReadWriteLock()Instantiates a new Atomic read write lock.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidasyncLock()Lock any writing for reading.voidasyncUnlock()Finish this reading and unlock any writing if it is last reading.protected voidconsumeCPU()Consume cpu.voidlock()voidlockInterruptibly()java.util.concurrent.locks.ConditionnewCondition()voidsyncLock()Lock any reading for writing.voidsyncUnlock()Finish this writing and unlock any readings.java.lang.StringtoString()booleantryLock()booleantryLock(long time, java.util.concurrent.TimeUnit unit)protected booleantryToLockReading()Try to lock reading boolean.protected booleantryToLockWriting()Try to lock writing boolean.voidunlock()
-
-
-
Field Detail
-
writeStatus
protected final java.util.concurrent.atomic.AtomicInteger writeStatus
The status of write lock.
-
writeCount
protected final java.util.concurrent.atomic.AtomicInteger writeCount
The count of writers.
-
readCount
protected final java.util.concurrent.atomic.AtomicInteger readCount
The count of readers.
-
sink
protected int sink
The field for consuming CPU.
-
-
Method Detail
-
asyncLock
public void asyncLock()
Description copied from interface:AsyncReadSyncWriteLockLock any writing for reading.- Specified by:
asyncLockin interfaceAsyncReadSyncWriteLock
-
asyncUnlock
public void asyncUnlock()
Description copied from interface:AsyncReadSyncWriteLockFinish this reading and unlock any writing if it is last reading.- Specified by:
asyncUnlockin interfaceAsyncReadSyncWriteLock
-
consumeCPU
protected void consumeCPU()
Consume cpu.
-
lock
public void lock()
- Specified by:
lockin interfacejava.util.concurrent.locks.Lock
-
lockInterruptibly
public void lockInterruptibly() throws java.lang.InterruptedException- Specified by:
lockInterruptiblyin interfacejava.util.concurrent.locks.Lock- Throws:
java.lang.InterruptedException
-
newCondition
public java.util.concurrent.locks.Condition newCondition()
- Specified by:
newConditionin interfacejava.util.concurrent.locks.Lock
-
syncLock
public void syncLock()
Description copied from interface:AsyncReadSyncWriteLockLock any reading for writing.- Specified by:
syncLockin interfaceAsyncReadSyncWriteLock
-
tryToLockWriting
protected boolean tryToLockWriting()
Try to lock writing boolean.- Returns:
- the boolean
-
tryToLockReading
protected boolean tryToLockReading()
Try to lock reading boolean.- Returns:
- the boolean
-
syncUnlock
public void syncUnlock()
Description copied from interface:AsyncReadSyncWriteLockFinish this writing and unlock any readings.- Specified by:
syncUnlockin interfaceAsyncReadSyncWriteLock
-
tryLock
public boolean tryLock()
- Specified by:
tryLockin interfacejava.util.concurrent.locks.Lock
-
tryLock
public boolean tryLock(long time, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException- Specified by:
tryLockin interfacejava.util.concurrent.locks.Lock- Throws:
java.lang.InterruptedException
-
unlock
public void unlock()
- Specified by:
unlockin interfacejava.util.concurrent.locks.Lock
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-