From 075b93ecd65cb8eee486e91b5db83620104b0d3c Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 26 Oct 2023 12:28:24 +0600 Subject: [PATCH] SmartRWLocker now will wait first unlock of write mutex for acquiring read --- CHANGELOG.md | 3 +++ .../kotlin/dev/inmo/micro_utils/coroutines/SmartRWLocker.kt | 1 + 2 files changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 533c805b582..0ee4ce87fea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## 0.20.11 +* `Coroutines`: + * `SmartRWLocker` now will wait first unlock of write mutex for acquiring read + ## 0.20.10 * `Versions`: diff --git a/coroutines/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/SmartRWLocker.kt b/coroutines/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/SmartRWLocker.kt index 7aaf845cb81..65eb1732bb6 100644 --- a/coroutines/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/SmartRWLocker.kt +++ b/coroutines/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/SmartRWLocker.kt @@ -23,6 +23,7 @@ class SmartRWLocker(private val readPermits: Int = Int.MAX_VALUE, writeIsLocked: * Do lock in [readSemaphore] inside of [writeMutex] locking */ suspend fun acquireRead() { + _writeMutex.waitUnlock() _readSemaphore.acquire() }