Closed autorain closed 2 months ago
Hey, there is no real reason.
This +2
was relevant in the earlier version of LFQ where instead of arraylets, a two-phased copy was used, and there was an additional invariant (the deque operation was two-phased, and there was an intermediate REMOVE
state).
You can read more here: https://github.com/Kotlin/kotlinx.coroutines/blob/5d94a264260c83f80b245020e27a742cd5b10983/core/kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental/internal/LockFreeMPSCQueue.kt
Why use
(tail + 2) and mask == head and mask
not(tail + 1) and mask == head and mask
? Could some kind person explain it to me? Thanks a lot.