Skip to content

Commit

Permalink
Workaround for KT-58685
Browse files Browse the repository at this point in the history
  • Loading branch information
CLOVIS-AI committed Sep 6, 2023
1 parent 862b554 commit 751364f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
9 changes: 6 additions & 3 deletions kotlinx-coroutines-core/common/src/sync/Mutex.kt
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,14 @@ public suspend inline fun <T> Mutex.withLock(owner: Any? = null, action: () -> T
}

lock(owner)
try {
return action()
} finally {
val result = try {
action()
} catch (e: Throwable) {
unlock(owner)
throw e
}
unlock(owner)
return result
}


Expand Down
9 changes: 6 additions & 3 deletions kotlinx-coroutines-core/common/src/sync/Semaphore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,14 @@ public suspend inline fun <T> Semaphore.withPermit(action: () -> T): T {
}

acquire()
try {
return action()
} finally {
val result = try {
action()
} catch (e: Throwable) {
release()
throw e
}
release()
return result
}

@Suppress("UNCHECKED_CAST")
Expand Down

0 comments on commit 751364f

Please sign in to comment.