Skip to content

Commit

Permalink
Merge pull request #2831 from Kotlin/concurrent-package
Browse files Browse the repository at this point in the history
Concurrent source-set for sharing between JVM and K/N
  • Loading branch information
mvicsokolova committed Jul 19, 2021
2 parents 190c0a1 + ca3e621 commit aebc889
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 198 deletions.
14 changes: 14 additions & 0 deletions kotlinx-coroutines-core/concurrent/src/Builders.concurrent.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/

package kotlinx.coroutines

import kotlin.coroutines.*

/**
* Runs a new coroutine and **blocks** the current thread until its completion.
* This function should not be used from a coroutine. It is designed to bridge regular blocking code
* to libraries that are written in suspending style, to be used in `main` functions and in tests.
*/
public expect fun <T> runBlocking(context: CoroutineContext = EmptyCoroutineContext, block: suspend CoroutineScope.() -> T): T
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package kotlinx.coroutines.internal

import kotlinx.atomicfu.*
import kotlinx.coroutines.*
import kotlin.jvm.*

private typealias Node = LockFreeLinkedListNode

Expand Down Expand Up @@ -616,7 +617,7 @@ public actual open class LockFreeLinkedListNode {
assert { next === this._next.value }
}

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

private class Removed(@JvmField val ref: Node) {
Expand Down
2 changes: 1 addition & 1 deletion kotlinx-coroutines-core/jvm/src/Builders.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import kotlin.coroutines.*
* @param block the coroutine code.
*/
@Throws(InterruptedException::class)
public fun <T> runBlocking(context: CoroutineContext = EmptyCoroutineContext, block: suspend CoroutineScope.() -> T): T {
public actual fun <T> runBlocking(context: CoroutineContext, block: suspend CoroutineScope.() -> T): T {
contract {
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
}
Expand Down
2 changes: 1 addition & 1 deletion kotlinx-coroutines-core/native/src/Builders.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import kotlin.coroutines.*
* @param context context of the coroutine. The default value is an implementation of [EventLoop].
* @param block the coroutine code.
*/
public fun <T> runBlocking(context: CoroutineContext = EmptyCoroutineContext, block: suspend CoroutineScope.() -> T): T {
public actual fun <T> runBlocking(context: CoroutineContext, block: suspend CoroutineScope.() -> T): T {
val contextInterceptor = context[ContinuationInterceptor]
val eventLoop: EventLoop?
var newContext: CoroutineContext = context // todo: kludge for data flow analysis error
Expand Down
22 changes: 0 additions & 22 deletions kotlinx-coroutines-core/native/src/CompletionHandler.kt

This file was deleted.

170 changes: 0 additions & 170 deletions kotlinx-coroutines-core/native/src/internal/LinkedList.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import kotlin.test.assertFalse
import kotlin.test.assertTrue

class LinkedListTest {
data class IntNode(val i: Int) : LinkedListNode()
data class IntNode(val i: Int) : LockFreeLinkedListNode()

@Test
fun testSimpleAddLastRemove() {
val list = LinkedListHead()
val list = LockFreeLinkedListHead()
assertContents(list)
val n1 = IntNode(1).apply { list.addLast(this) }
assertContents(list, 1)
Expand All @@ -35,7 +35,7 @@ class LinkedListTest {
assertContents(list)
}

private fun assertContents(list: LinkedListHead, vararg expected: Int) {
private fun assertContents(list: LockFreeLinkedListHead, vararg expected: Int) {
val n = expected.size
val actual = IntArray(n)
var index = 0
Expand Down

0 comments on commit aebc889

Please sign in to comment.