From 13132e7483778b4828b6fda8b3c8fee8c82ce1c3 Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Tue, 22 Sep 2015 17:20:09 +0300 Subject: [PATCH] Move `synchronized` method out of JLangJVM --- libraries/stdlib/src/kotlin/util/JLangJVM.kt | 14 +------------- .../stdlib/src/kotlin/util/Synchronized.kt | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 13 deletions(-) create mode 100644 libraries/stdlib/src/kotlin/util/Synchronized.kt diff --git a/libraries/stdlib/src/kotlin/util/JLangJVM.kt b/libraries/stdlib/src/kotlin/util/JLangJVM.kt index 135a654688d..011060518ab 100644 --- a/libraries/stdlib/src/kotlin/util/JLangJVM.kt +++ b/libraries/stdlib/src/kotlin/util/JLangJVM.kt @@ -41,18 +41,6 @@ public val T.javaClass : Class @Deprecated("Use the class reference and .java extension property instead: MyClass::class.java", ReplaceWith("T::class.java")) public fun javaClass(): Class = T::class.java -/** - * Executes the given function [block] while holding the monitor of the given object [lock]. - */ -public inline fun synchronized(lock: Any, block: () -> R): R { - monitorEnter(lock) - try { - return block() - } - finally { - monitorExit(lock) - } -} /** * Returns the annotation type of this annotation. @@ -66,4 +54,4 @@ public fun T.annotationType() : Class = @Suppress("NOTHING_TO_INLINE") public inline fun Method.invoke(instance: Any, vararg args: Any?): Any? { return invoke(instance, *args) -} \ No newline at end of file +} diff --git a/libraries/stdlib/src/kotlin/util/Synchronized.kt b/libraries/stdlib/src/kotlin/util/Synchronized.kt new file mode 100644 index 00000000000..56723d0289e --- /dev/null +++ b/libraries/stdlib/src/kotlin/util/Synchronized.kt @@ -0,0 +1,17 @@ +@file:JvmVersion +package kotlin + +import kotlin.jvm.internal.unsafe.* + +/** + * Executes the given function [block] while holding the monitor of the given object [lock]. + */ +public inline fun synchronized(lock: Any, block: () -> R): R { + monitorEnter(lock) + try { + return block() + } + finally { + monitorExit(lock) + } +}