JvmName annotations for beautiful mangling and binary compatibility
This commit is contained in:
parent
e3d0aabd0f
commit
7dabea756f
@ -5,6 +5,7 @@ package ru.landrafhomyak.utility.reference_counter
|
||||
import kotlin.contracts.ExperimentalContracts
|
||||
import kotlin.contracts.InvocationKind
|
||||
import kotlin.contracts.contract
|
||||
import kotlin.jvm.JvmName
|
||||
import ru.landgrafhomyak.utility.highlevel_try_finally.safeAutoClose1
|
||||
import ru.landgrafhomyak.utility.highlevel_try_finally.safeAutoClose2
|
||||
|
||||
@ -18,10 +19,12 @@ public class CloseableReferenceCounter {
|
||||
this._value = _AtomicLong(0L)
|
||||
}
|
||||
|
||||
@JvmName("throwClosed")
|
||||
public fun throwClosed() {
|
||||
throw IllegalStateException(this._errMessageClosed)
|
||||
}
|
||||
|
||||
@JvmName("incref")
|
||||
public fun incref() {
|
||||
this._value.update { o ->
|
||||
if (o < 0) this.throwClosed()
|
||||
@ -29,6 +32,7 @@ public class CloseableReferenceCounter {
|
||||
}
|
||||
}
|
||||
|
||||
@JvmName("tryIncref\$kt")
|
||||
public inline fun <R> tryIncref(block: () -> R): R {
|
||||
contract {
|
||||
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
|
||||
@ -37,14 +41,17 @@ public class CloseableReferenceCounter {
|
||||
return safeAutoClose2(onError = this::decref, action = block)
|
||||
}
|
||||
|
||||
@JvmName("assertNotClosed")
|
||||
public fun assertNotClosed() {
|
||||
if (this._value.get() < 0) this.throwClosed()
|
||||
}
|
||||
|
||||
@JvmName("decref")
|
||||
public fun decref() {
|
||||
this._value.update(Long::dec)
|
||||
}
|
||||
|
||||
@JvmName("tryDecref\$kt")
|
||||
public inline fun <R> tryDecref(block: () -> R): R {
|
||||
contract {
|
||||
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
|
||||
@ -53,8 +60,10 @@ public class CloseableReferenceCounter {
|
||||
return safeAutoClose2(onSuccess = this::decref, action = block)
|
||||
}
|
||||
|
||||
@get:JvmName("isClosed")
|
||||
public val isClosed: Boolean get() = this._value.get() < 0
|
||||
|
||||
@JvmName("close")
|
||||
public fun close(errExistRefs: String) {
|
||||
_Platform.jvm_assertNotNull(errExistRefs, "param: errExistRefs")
|
||||
val state = _CloseableReferenceCounter_LowLevel.compareAndExchange(this._value, 0, _CloseableReferenceCounter_LowLevel.CLOSED_STATE_VALUE)
|
||||
@ -64,6 +73,7 @@ public class CloseableReferenceCounter {
|
||||
}
|
||||
}
|
||||
|
||||
@JvmName("withRef\$kt")
|
||||
public inline fun <R> withRef(protected: () -> R): R {
|
||||
this.incref()
|
||||
return safeAutoClose1(finally = this::decref, action = protected)
|
||||
|
@ -5,6 +5,7 @@ package ru.landrafhomyak.utility.reference_counter
|
||||
import kotlin.contracts.ExperimentalContracts
|
||||
import kotlin.contracts.InvocationKind
|
||||
import kotlin.contracts.contract
|
||||
import kotlin.jvm.JvmName
|
||||
import ru.landgrafhomyak.utility.highlevel_try_finally.safeAutoClose1
|
||||
import ru.landgrafhomyak.utility.highlevel_try_finally.safeAutoClose2
|
||||
|
||||
@ -47,14 +48,17 @@ public class CloseableReferenceCounter_Debug {
|
||||
}
|
||||
|
||||
@RequiresExplicitDebug
|
||||
@JvmName("throwErrors")
|
||||
public fun throwErrors() {
|
||||
this._throwErrors(this._value.get())
|
||||
}
|
||||
|
||||
@JvmName("throwClosed")
|
||||
public fun throwClosed() {
|
||||
throw IllegalStateException(this._errMessage)
|
||||
}
|
||||
|
||||
@JvmName("incref")
|
||||
public fun incref() {
|
||||
this._value.update { o ->
|
||||
if (o < 0) {
|
||||
@ -67,6 +71,7 @@ public class CloseableReferenceCounter_Debug {
|
||||
this._logger?.observeState(this, "incref")
|
||||
}
|
||||
|
||||
@JvmName("tryIncref\$kt")
|
||||
public inline fun <R> tryIncref(block: () -> R): R {
|
||||
contract {
|
||||
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
|
||||
@ -75,10 +80,12 @@ public class CloseableReferenceCounter_Debug {
|
||||
return safeAutoClose2(onError = this::decref, action = block)
|
||||
}
|
||||
|
||||
@JvmName("assertNotClosed")
|
||||
public fun assertNotClosed() {
|
||||
if (this._value.get() < 0) this.throwClosed()
|
||||
}
|
||||
|
||||
@JvmName("decref")
|
||||
public fun decref() {
|
||||
this._value.update { o ->
|
||||
if (o < 0) {
|
||||
@ -91,6 +98,7 @@ public class CloseableReferenceCounter_Debug {
|
||||
this._logger?.observeState(this, "decref")
|
||||
}
|
||||
|
||||
@JvmName("tryDecref\$kt")
|
||||
public inline fun <R> tryDecref(block: () -> R): R {
|
||||
contract {
|
||||
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
|
||||
@ -99,6 +107,7 @@ public class CloseableReferenceCounter_Debug {
|
||||
return safeAutoClose2(onSuccess = this::decref, action = block)
|
||||
}
|
||||
|
||||
@get:JvmName("isClosed")
|
||||
public val isClosed: Boolean
|
||||
get() {
|
||||
val state = this._value.get()
|
||||
@ -106,6 +115,7 @@ public class CloseableReferenceCounter_Debug {
|
||||
return state < 0;
|
||||
}
|
||||
|
||||
@JvmName("close")
|
||||
public fun close(errExistRefs: String) {
|
||||
_Platform.jvm_assertNotNull(errExistRefs, "param: errExistRefs")
|
||||
val state = _CloseableReferenceCounter_LowLevel.compareAndExchange(this._value, 0, _CloseableReferenceCounter_LowLevel.CLOSED_STATE_VALUE)
|
||||
@ -117,6 +127,7 @@ public class CloseableReferenceCounter_Debug {
|
||||
this._logger?.observeState(this, "closed")
|
||||
}
|
||||
|
||||
@JvmName("withRef\$kt")
|
||||
public inline fun <R> withRef(protected: () -> R): R {
|
||||
this.incref()
|
||||
return safeAutoClose1(finally = this::decref, action = protected)
|
||||
|
Loading…
Reference in New Issue
Block a user