# SmartKeyRWLocker

class SmartKeyRWLocker < T >(globalLockerReadPermits: Int = Int.MAX_VALUE, globalLockerWriteIsLocked: Boolean = false, perKeyReadPermits: Int = Int.MAX_VALUE)(source)

Combining globalRWLocker and internal map of SmartRWLocker associated by T to provide next logic:

- Locker by key, for reading: waiting for globalRWLocker unlock write by acquiring read permit in it and then taking or creating locker for key T and lock its reading too

- Locker by key, for writing: waiting for globalRWLocker unlock write by acquiring read permit in it and then taking or creating locker for key T and lock its writing

- globalRWLocker, for reading: using SmartRWLocker.acquireRead, will be suspended until its SmartRWLocker.lockWrite will not be unlocked

- globalRWLocker, for writing: using SmartRWLocker.lockWrite, will be paused by other reading and writing operations and will pause other operations until the end of operation (calling of unlockWrite)

You may see, that lockers by key still will use global locker permits - it is required to prevent globalRWLocker write locking during all other operations are not done. In fact, all the keys works like a simple SmartRWLocker as well, as globalRWLocker, but they are linked with globalRWLocker permissions

## Constructors

SmartKeyRWLocker
Link copied to clipboard
constructor(globalLockerReadPermits: Int = Int.MAX_VALUE, globalLockerWriteIsLocked: Boolean = false, perKeyReadPermits: Int = Int.MAX_VALUE)

## Functions

acquireRead
Link copied to clipboard
suspend fun acquireRead ()
suspend fun acquireRead (key: T )
isWriteLocked
Link copied to clipboard
fun isWriteLocked (): Boolean
fun isWriteLocked (key: T ): Boolean
lockWrite
Link copied to clipboard
suspend fun lockWrite ()
suspend fun lockWrite (key: T )
readSemaphore
Link copied to clipboard
fun readSemaphore (): SmartSemaphore.Immutable
suspend fun readSemaphore (key: T ): SmartSemaphore.Immutable
readSemaphoreOrNull
Link copied to clipboard
fun readSemaphoreOrNull (key: T ): SmartSemaphore.Immutable ?
releaseRead
Link copied to clipboard
suspend fun releaseRead (): Boolean
suspend fun releaseRead (key: T ): Boolean
unlockWrite
Link copied to clipboard
suspend fun unlockWrite (): Boolean
suspend fun unlockWrite (key: T ): Boolean
withReadAcquire
Link copied to clipboard
inline suspend fun < T , R > SmartKeyRWLocker < T >. withReadAcquire (action: () -> R ): R
inline suspend fun < T , R > SmartKeyRWLocker < T >. withReadAcquire (key: T , action: () -> R ): R
withReadAcquires
Link copied to clipboard
inline suspend fun < T , R > SmartKeyRWLocker < T >. withReadAcquires (keys: Iterable < T >, action: () -> R ): R
inline suspend fun < T , R > SmartKeyRWLocker < T >. withReadAcquires (vararg keys: T , action: () -> R ): R
withWriteLock
Link copied to clipboard
inline suspend fun < T , R > SmartKeyRWLocker < T >. withWriteLock (action: () -> R ): R
inline suspend fun < T , R > SmartKeyRWLocker < T >. withWriteLock (key: T , action: () -> R ): R
withWriteLocks
Link copied to clipboard
inline suspend fun < T , R > SmartKeyRWLocker < T >. withWriteLocks (keys: Iterable < T >, action: () -> R ): R
inline suspend fun < T , R > SmartKeyRWLocker < T >. withWriteLocks (vararg keys: T , action: () -> R ): R
writeMutex
Link copied to clipboard
fun writeMutex (): SmartMutex.Immutable
suspend fun writeMutex (key: T ): SmartMutex.Immutable
writeMutexOrNull
Link copied to clipboard
fun writeMutexOrNull (key: T ): SmartMutex.Immutable ?