Skip to content

Commit a4becc9

Browse files
committed
Guard LockSupport.unpark with Thread.currentThread() checks for better performance
1 parent 45fb9f9 commit a4becc9

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental/Builders.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ private class BlockingCoroutine<T>(
9191
init { initParentJob(newContext[Job]) }
9292

9393
override fun afterCompletion(state: Any?) {
94-
LockSupport.unpark(blockedThread)
94+
if (Thread.currentThread() != blockedThread)
95+
LockSupport.unpark(blockedThread)
9596
}
9697

9798
@Suppress("UNCHECKED_CAST")

kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental/EventLoop.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ internal class EventLoopImpl(
6969
} else
7070
queue.addLastIf(node) { parentJob!!.isActive }
7171
if (added) {
72-
LockSupport.unpark(thread)
72+
if (Thread.currentThread() != thread)
73+
LockSupport.unpark(thread)
7374
} else {
7475
node.run()
7576
}

0 commit comments

Comments
 (0)