Skip to content

Commit ca3e621

Browse files
committed
Concurrent source-set for sharing between JVM and K/N
1 parent 190c0a1 commit ca3e621

File tree

8 files changed

+21
-198
lines changed

8 files changed

+21
-198
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
package kotlinx.coroutines
6+
7+
import kotlin.coroutines.*
8+
9+
/**
10+
* Runs a new coroutine and **blocks** the current thread until its completion.
11+
* This function should not be used from a coroutine. It is designed to bridge regular blocking code
12+
* to libraries that are written in suspending style, to be used in `main` functions and in tests.
13+
*/
14+
public expect fun <T> runBlocking(context: CoroutineContext = EmptyCoroutineContext, block: suspend CoroutineScope.() -> T): T

kotlinx-coroutines-core/jvm/src/internal/LockFreeLinkedList.kt renamed to kotlinx-coroutines-core/concurrent/src/internal/LockFreeLinkedList.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package kotlinx.coroutines.internal
77

88
import kotlinx.atomicfu.*
99
import kotlinx.coroutines.*
10+
import kotlin.jvm.*
1011

1112
private typealias Node = LockFreeLinkedListNode
1213

@@ -616,7 +617,7 @@ public actual open class LockFreeLinkedListNode {
616617
assert { next === this._next.value }
617618
}
618619

619-
override fun toString(): String = "${this::class.java.simpleName}@${Integer.toHexString(System.identityHashCode(this))}"
620+
override fun toString(): String = "${this::classSimpleName}@${this.hexAddress}"
620621
}
621622

622623
private class Removed(@JvmField val ref: Node) {

kotlinx-coroutines-core/jvm/src/Builders.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import kotlin.coroutines.*
3535
* @param block the coroutine code.
3636
*/
3737
@Throws(InterruptedException::class)
38-
public fun <T> runBlocking(context: CoroutineContext = EmptyCoroutineContext, block: suspend CoroutineScope.() -> T): T {
38+
public actual fun <T> runBlocking(context: CoroutineContext, block: suspend CoroutineScope.() -> T): T {
3939
contract {
4040
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
4141
}

kotlinx-coroutines-core/native/src/Builders.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import kotlin.coroutines.*
3030
* @param context context of the coroutine. The default value is an implementation of [EventLoop].
3131
* @param block the coroutine code.
3232
*/
33-
public fun <T> runBlocking(context: CoroutineContext = EmptyCoroutineContext, block: suspend CoroutineScope.() -> T): T {
33+
public actual fun <T> runBlocking(context: CoroutineContext, block: suspend CoroutineScope.() -> T): T {
3434
val contextInterceptor = context[ContinuationInterceptor]
3535
val eventLoop: EventLoop?
3636
var newContext: CoroutineContext = context // todo: kludge for data flow analysis error

kotlinx-coroutines-core/native/src/CompletionHandler.kt

-22
This file was deleted.

kotlinx-coroutines-core/native/src/internal/LinkedList.kt

-170
This file was deleted.

kotlinx-coroutines-core/native/test/internal/LinkedListTest.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import kotlin.test.assertFalse
1010
import kotlin.test.assertTrue
1111

1212
class LinkedListTest {
13-
data class IntNode(val i: Int) : LinkedListNode()
13+
data class IntNode(val i: Int) : LockFreeLinkedListNode()
1414

1515
@Test
1616
fun testSimpleAddLastRemove() {
17-
val list = LinkedListHead()
17+
val list = LockFreeLinkedListHead()
1818
assertContents(list)
1919
val n1 = IntNode(1).apply { list.addLast(this) }
2020
assertContents(list, 1)
@@ -35,7 +35,7 @@ class LinkedListTest {
3535
assertContents(list)
3636
}
3737

38-
private fun assertContents(list: LinkedListHead, vararg expected: Int) {
38+
private fun assertContents(list: LockFreeLinkedListHead, vararg expected: Int) {
3939
val n = expected.size
4040
val actual = IntArray(n)
4141
var index = 0

0 commit comments

Comments
 (0)