Commit 94b644f
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).
Additionally, change also reduces amount of wasteful helping and
starvation of ConflatedChannel receiver with many senders:
* removeFirstIfIsInstanceOfOrPeekIf that is used to take the first
element from a channel does not need help every time when
it finds a removed element, but quickly tries the next element
to see if it can remove that one instead for a few times.
* conflatePreviousSendBuffered does not help with removal when its own
node was removed.1 parent bbf198b commit 94b644f
File tree
6 files changed
+176
-200
lines changed- kotlinx-coroutines-core
- common/src
- channels
- internal
- js/src/internal
- jvm
- src/internal
- test/channels
- native/src/internal
6 files changed
+176
-200
lines changedLines changed: 5 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | 7 | | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
50 | | - | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
51 | 52 | | |
52 | 53 | | |
53 | 54 | | |
54 | 55 | | |
55 | | - | |
| 56 | + | |
56 | 57 | | |
57 | 58 | | |
58 | 59 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| |||
0 commit comments