Skip to content

Commit 03b6d1d

Browse files
committed
Simpler and faster lock-free linked list
Lock-free list implementation is considerably simplified, taking into account a limited number of operations that it needs to support. * prev pointers in the list are not marked for removal, since we don't need to support linearizable backwards iteration. * helpDelete method is completely removed. All "delete-helping" is performed only by correctPrev method. * correctPrev method bails out when the node it works on is removed to reduce contention during concurrent removals. * Special open methods "isRemoved" and "nextIfRemoved" are introduced and are overridden in list head class (which is never removed). This ensures that on long list "removeFist" operation (touching head) does not interfere with "addLast" (touch tail). There is still sharing of cache-lines in this case, but no helping between them. All in all, this improvement reduces the size of implementation code and makes it considerably faster. Operations on LinkedListChannel are now much faster (see timings of ChannelSendReceiveStressTest).
1 parent 0126dba commit 03b6d1d

File tree

3 files changed

+155
-198
lines changed

3 files changed

+155
-198
lines changed

Diff for: kotlinx-coroutines-core/common/src/channels/ConflatedChannel.kt

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1+
/*
2+
* Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
15
package kotlinx.coroutines.channels
26

37
import kotlinx.coroutines.*
48
import kotlinx.coroutines.internal.*
59
import kotlinx.coroutines.selects.*
6-
import kotlin.native.concurrent.SharedImmutable
10+
import kotlin.native.concurrent.*
711

812
/**
913
* Channel that buffers at most one element and conflates all subsequent `send` and `offer` invocations,
1014
* so that the receiver always gets the most recently sent element.
11-
* Back-to-send sent elements are _conflated_ -- only the the most recently sent element is received,
15+
* Back-to-send sent elements are _conflated_ -- only the most recently sent element is received,
1216
* while previously sent elements **are lost**.
1317
* Sender to this channel never suspends and [offer] always returns `true`.
1418
*

0 commit comments

Comments
 (0)