[history] Added .tryDecref{} as opposite operation for .tryIncref{}

This commit is contained in:
Andrew Golovashevich 2025-03-19 00:37:46 +03:00
parent be4c578491
commit f37d81cd60

View File

@ -33,6 +33,11 @@ internal class CloseableReferenceCounter(private val _errMessage: String) {
this._value.update(Long::dec)
}
inline fun <R> tryDecref(block: () -> R): R {
this.checkNotClosed()
return safeAutoClose2(onSuccess = this::decref, action = block)
}
fun close(errExistRefs: String) {
val state = this._value.compareAndExchange(0, -1)
when {