SmartRWLocker

class SmartRWLocker(readPermits: Int = Int.MAX_VALUE, writeIsLocked: Boolean = false)(source)

Composite mutex which works with next rules:

Constructors

Link copied to clipboard
constructor(readPermits: Int = Int.MAX_VALUE, writeIsLocked: Boolean = false)

Properties

Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
suspend fun acquireRead()

Do lock in readSemaphore inside of writeMutex locking

Link copied to clipboard
suspend fun lockWrite()

Locking writeMutex and wait while all readSemaphore permits will be freed

Link copied to clipboard
suspend fun releaseRead(): Boolean

Release one read permit in readSemaphore

Link copied to clipboard
suspend fun unlockWrite(): Boolean

Unlock writeMutex

Link copied to clipboard
suspend fun SmartRWLocker.waitReadRelease(permits: Int = 1): Int

Will wait until the SmartSemaphore.permitsStateFlow of this instance will have permits count free permits.

Link copied to clipboard

Will wait until the SmartMutex.lockStateFlow of this instance will be false.

Link copied to clipboard
inline suspend fun <T> SmartRWLocker.withReadAcquire(action: () -> T): T

Will call SmartSemaphore.Mutable.lock, then execute action and return the result after SmartSemaphore.Mutable.unlock

Link copied to clipboard
inline suspend fun <T> SmartRWLocker.withWriteLock(action: () -> T): T

Will call SmartMutex.Mutable.lock, then execute action and return the result after SmartMutex.Mutable.unlock