isClosed property

This commit is contained in:
Andrew Golovashevich 2025-03-26 01:57:41 +03:00
parent 6581c14072
commit e3d0aabd0f
2 changed files with 9 additions and 1 deletions

View File

@ -53,6 +53,8 @@ public class CloseableReferenceCounter {
return safeAutoClose2(onSuccess = this::decref, action = block) return safeAutoClose2(onSuccess = this::decref, action = block)
} }
public val isClosed: Boolean get() = this._value.get() < 0
public fun close(errExistRefs: String) { public fun close(errExistRefs: String) {
_Platform.jvm_assertNotNull(errExistRefs, "param: errExistRefs") _Platform.jvm_assertNotNull(errExistRefs, "param: errExistRefs")
val state = _CloseableReferenceCounter_LowLevel.compareAndExchange(this._value, 0, _CloseableReferenceCounter_LowLevel.CLOSED_STATE_VALUE) val state = _CloseableReferenceCounter_LowLevel.compareAndExchange(this._value, 0, _CloseableReferenceCounter_LowLevel.CLOSED_STATE_VALUE)

View File

@ -37,7 +37,6 @@ public class CloseableReferenceCounter_Debug {
} }
@Suppress("NOTHING_TO_INLINE") @Suppress("NOTHING_TO_INLINE")
private inline fun _throwErrors(valueToCheck: Long) { private inline fun _throwErrors(valueToCheck: Long) {
when { when {
@ -100,6 +99,13 @@ public class CloseableReferenceCounter_Debug {
return safeAutoClose2(onSuccess = this::decref, action = block) return safeAutoClose2(onSuccess = this::decref, action = block)
} }
public val isClosed: Boolean
get() {
val state = this._value.get()
this._throwErrors(state)
return state < 0;
}
public fun close(errExistRefs: String) { public fun close(errExistRefs: String) {
_Platform.jvm_assertNotNull(errExistRefs, "param: errExistRefs") _Platform.jvm_assertNotNull(errExistRefs, "param: errExistRefs")
val state = _CloseableReferenceCounter_LowLevel.compareAndExchange(this._value, 0, _CloseableReferenceCounter_LowLevel.CLOSED_STATE_VALUE) val state = _CloseableReferenceCounter_LowLevel.compareAndExchange(this._value, 0, _CloseableReferenceCounter_LowLevel.CLOSED_STATE_VALUE)