It is defined as:
@kotlin.internal.InlineOnly
public inline fun <R> synchronized(lock: Any, block: () -> R): R {
@Suppress("NON_PUBLIC_CALL_FROM_PUBLIC_INLINE")
monitorEnter(lock)
try {
return block()
}
finally {
@Suppress("NON_PUBLIC_CALL_FROM_PUBLIC_INLINE")
monitorExit(lock)
}
}
Am I correct that there is some compiler magic going on for monitorEnter()
and monitorExit()
?
What does @kotlin.internal.InlineOnly
do in this context? As the function is specified as inline
, are there any ways that call may not be inlined?