|
16 | 16 |
|
17 | 17 | package kotlinx.coroutines.experimental.channels
|
18 | 18 |
|
19 |
| -import kotlinx.coroutines.experimental.CancellableContinuation |
20 |
| -import kotlinx.coroutines.experimental.DisposableHandle |
| 19 | +import kotlinx.coroutines.experimental.* |
21 | 20 | import kotlinx.coroutines.experimental.internal.*
|
22 |
| -import kotlinx.coroutines.experimental.intrinsics.startCoroutineUndispatched |
23 |
| -import kotlinx.coroutines.experimental.removeOnCancel |
24 |
| -import kotlinx.coroutines.experimental.selects.ALREADY_SELECTED |
25 |
| -import kotlinx.coroutines.experimental.selects.SelectClause1 |
26 |
| -import kotlinx.coroutines.experimental.selects.SelectClause2 |
27 |
| -import kotlinx.coroutines.experimental.selects.SelectInstance |
28 |
| -import kotlinx.coroutines.experimental.suspendAtomicCancellableCoroutine |
29 |
| -import kotlin.coroutines.experimental.startCoroutine |
| 21 | +import kotlinx.coroutines.experimental.intrinsics.* |
| 22 | +import kotlinx.coroutines.experimental.selects.* |
| 23 | +import kotlin.coroutines.experimental.* |
30 | 24 |
|
31 | 25 | /**
|
32 | 26 | * Abstract send channel. It is a base class for all send channel implementations.
|
@@ -374,6 +368,37 @@ public abstract class AbstractSendChannel<E> : SendChannel<E> {
|
374 | 368 | }
|
375 | 369 | }
|
376 | 370 |
|
| 371 | + // ------ debug ------ |
| 372 | + |
| 373 | + public override fun toString() = |
| 374 | + "$classSimpleName@$hexAddress{$queueDebugStateString}$bufferDebugString" |
| 375 | + |
| 376 | + private val queueDebugStateString: String |
| 377 | + get() { |
| 378 | + val head = queue.next |
| 379 | + if (head === queue) return "EmptyQueue" |
| 380 | + var result = when (head) { |
| 381 | + is Closed<*> -> head.toString() |
| 382 | + is Receive<*> -> "ReceiveQueued" |
| 383 | + is Send -> "SendQueued" |
| 384 | + else -> "UNEXPECTED:$head" // should not happen |
| 385 | + } |
| 386 | + val tail = queue.prev |
| 387 | + if (tail !== head) { |
| 388 | + result += ",queueSize=${countQueueSize()}" |
| 389 | + if (tail is Closed<*>) result += ",closedForSend=$tail" |
| 390 | + } |
| 391 | + return result |
| 392 | + } |
| 393 | + |
| 394 | + private fun countQueueSize(): Int { |
| 395 | + var size = 0 |
| 396 | + queue.forEach<LockFreeLinkedListNode> { size++ } |
| 397 | + return size |
| 398 | + } |
| 399 | + |
| 400 | + protected open val bufferDebugString: String get() = "" |
| 401 | + |
377 | 402 | // ------ private ------
|
378 | 403 |
|
379 | 404 | private class SendSelect<E, R>(
|
|
0 commit comments