Skip to content

Commit b099acc

Browse files
committed
change remove()
1 parent 58a21ea commit b099acc

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

kotlinx-coroutines-core/common/src/channels/BufferedChannel.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2512,8 +2512,8 @@ internal open class BufferedChannel<E>(
25122512
This method is used in the physical removal of the segment. It helps to move pointers forward from
25132513
the segment which was physically removed.
25142514
*/
2515-
internal fun movePointersForwardFrom(from: ChannelSegment<E>) {
2516-
check(from.isRemoved) { "Trying to move channel pointers from the alive segment." }
2515+
internal fun movePointersForwardFromRemovedSegment(from: ChannelSegment<E>) {
2516+
if (!from.isRemoved) return
25172517
if (from == sendSegment.value) sendSegment.moveToSpecifiedOrLast(from.id, from)
25182518
if (from == receiveSegment.value) receiveSegment.moveToSpecifiedOrLast(from.id, from)
25192519
if (from == bufferEndSegment.value) bufferEndSegment.moveToSpecifiedOrLast(from.id, from)
@@ -2785,13 +2785,13 @@ internal class ChannelSegment<E>(id: Long, prev: ChannelSegment<E>?, channel: Bu
27852785
/**
27862786
* Removes the segment physically from the segment list.
27872787
*
2788-
* If the physical removal was successful and there are channel pointers pointing on this segment,
2789-
* the [BufferedChannel.movePointersForwardFrom] method is invoked to move them further on the segment list.
2788+
* After the physical removal is finished and there are channel pointers referencing the removed segment,
2789+
* the [BufferedChannel.movePointersForwardFromRemovedSegment] method is invoked to move them further on the segment list.
27902790
*/
2791-
override fun remove(): Boolean =
2792-
super.remove().also {
2793-
if (it) channel.movePointersForwardFrom(this)
2794-
}
2791+
override fun remove() {
2792+
super.remove()
2793+
channel.movePointersForwardFromRemovedSegment(this)
2794+
}
27952795

27962796
// ########################
27972797
// # Cancellation Support #

kotlinx-coroutines-core/common/src/internal/ConcurrentLinkedList.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,11 @@ internal abstract class ConcurrentLinkedListNode<N : ConcurrentLinkedListNode<N>
200200
*
201201
* Returns `true`, if the node was physically removed, and `false` otherwise.
202202
*/
203-
open fun remove(): Boolean {
203+
open fun remove() {
204204
assert { isRemoved || isTail } // The node should be logically removed at first.
205205
// The physical tail cannot be removed. Instead, we remove it when
206206
// a new segment is added and this segment is not the tail one anymore.
207-
if (isTail) return false
207+
if (isTail) return
208208
while (true) {
209209
// Read `next` and `prev` pointers ignoring logically removed nodes.
210210
val prev = aliveSegmentLeft
@@ -216,7 +216,7 @@ internal abstract class ConcurrentLinkedListNode<N : ConcurrentLinkedListNode<N>
216216
if (next.isRemoved && !next.isTail) continue
217217
if (prev !== null && prev.isRemoved) continue
218218
// This node is removed.
219-
return true
219+
return
220220
}
221221
}
222222

0 commit comments

Comments
 (0)