KT-4825 Implement "synchronized" properly via monitorenter/monitorexit
#KT-4825 Fixed
This commit is contained in:
@@ -2,6 +2,7 @@ package kotlin
|
||||
|
||||
import java.lang.annotation.Retention
|
||||
import java.lang.annotation.RetentionPolicy
|
||||
import kotlin.jvm.internal.unsafe.*
|
||||
import kotlin.jvm.internal.Intrinsic
|
||||
|
||||
/**
|
||||
@@ -24,7 +25,15 @@ public annotation class throws(vararg val exceptionClasses: Class<out Throwable>
|
||||
|
||||
[Intrinsic("kotlin.javaClass.function")] fun <reified T> javaClass() : Class<T> = null as Class<T>
|
||||
|
||||
[Intrinsic("kotlin.synchronized")] public fun <R> synchronized(lock: Any, block: () -> R): R = block()
|
||||
public inline fun <R> synchronized(lock: Any, block: () -> R): R {
|
||||
monitorEnter(lock)
|
||||
try {
|
||||
return block()
|
||||
}
|
||||
finally {
|
||||
monitorExit(lock)
|
||||
}
|
||||
}
|
||||
|
||||
public fun <T : Annotation> T.annotationType() : Class<out T> =
|
||||
(this as java.lang.annotation.Annotation).annotationType() as Class<out T>
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright 2010-2014 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package kotlin.jvm.internal.unsafe
|
||||
|
||||
import kotlin.jvm.internal.Intrinsic
|
||||
|
||||
[Intrinsic("kotlin.jvm.internal.unsafe.monitorEnter")]
|
||||
public fun monitorEnter(monitor: Any): Unit = throw UnsupportedOperationException("This function can only be used privately")
|
||||
|
||||
[Intrinsic("kotlin.jvm.internal.unsafe.monitorExit")]
|
||||
public fun monitorExit(monitor: Any): Unit = throw UnsupportedOperationException("This function can only be used privately")
|
||||
Reference in New Issue
Block a user