Skip to content

Commit 4e33cc6

Browse files
committed
Custom synchronized stub in common code for JVM/JS/Native
It is needed for Kotlin/Native 0.9 migration
1 parent 43c0743 commit 4e33cc6

File tree

6 files changed

+49
-3
lines changed

6 files changed

+49
-3
lines changed

common/kotlinx-coroutines-core-common/src/JobSupport.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,7 @@ internal open class JobSupport constructor(active: Boolean) : Job, SelectClause0
853853
override val list: NodeList,
854854
@JvmField val cancelled: Cancelled?, /* != null when cancelling */
855855
@JvmField val completing: Boolean /* true when completing */
856-
) : Incomplete {
856+
) : SynchronizedObject(), Incomplete {
857857
override val isActive: Boolean get() = cancelled == null
858858

859859
// guarded by `synchronized(this)`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
2+
* Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
package kotlinx.coroutines.experimental.internal
6+
7+
internal expect open class SynchronizedObject() // marker abstract class
8+
9+
@PublishedApi
10+
internal expect inline fun <T> synchronized(lock: SynchronizedObject, block: () -> T): T
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
package kotlinx.coroutines.experimental.internal
6+
7+
@Suppress("ACTUAL_WITHOUT_EXPECT") // visibility
8+
internal actual typealias SynchronizedObject = Any
9+
10+
@PublishedApi
11+
internal actual inline fun <T> synchronized(lock: SynchronizedObject, block: () -> T): T =
12+
kotlin.synchronized(lock, block)

core/kotlinx-coroutines-core/src/internal/ThreadSafeHeap.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public interface ThreadSafeHeapNode {
1818
*
1919
* @suppress **This is unstable API and it is subject to change.**
2020
*/
21-
public class ThreadSafeHeap<T> where T: ThreadSafeHeapNode, T: Comparable<T> {
21+
public class ThreadSafeHeap<T> : SynchronizedObject() where T: ThreadSafeHeapNode, T: Comparable<T> {
2222
private var a: Array<T?>? = null
2323

2424
@JvmField @PublishedApi @Volatile
@@ -96,7 +96,7 @@ public class ThreadSafeHeap<T> where T: ThreadSafeHeapNode, T: Comparable<T> {
9696
@PublishedApi
9797
internal fun addImpl(node: T) {
9898
val a = realloc()
99-
var i = size++
99+
val i = size++
100100
a[i] = node
101101
node.index = i
102102
siftUpFrom(i)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
package kotlinx.coroutines.experimental.internal
6+
7+
@Suppress("ACTUAL_WITHOUT_EXPECT") // visibility
8+
internal actual typealias SynchronizedObject = Any
9+
10+
@PublishedApi
11+
internal actual inline fun <T> synchronized(lock: SynchronizedObject, block: () -> T): T =
12+
block()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
package kotlinx.coroutines.experimental.internal
6+
7+
@Suppress("ACTUAL_WITHOUT_EXPECT") // visibility
8+
internal actual typealias SynchronizedObject = Any
9+
10+
@PublishedApi
11+
internal actual inline fun <T> synchronized(lock: SynchronizedObject, block: () -> T): T =
12+
block()

0 commit comments

Comments
 (0)