Skip to content

Commit cfc08ee

Browse files
ndkovalelizarov
authored andcommitted
All ArrayChannel.size accesses should be under the channel lock
1 parent c5a42da commit cfc08ee

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

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

+2-6
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,12 @@ internal open class ArrayChannel<E>(
3636
*/
3737
private var buffer: Array<Any?> = arrayOfNulls<Any?>(min(capacity, 8))
3838
private var head: Int = 0
39-
40-
private val _size = atomic(0)
41-
private var size: Int // Invariant: size <= capacity
42-
get() = _size.value
43-
set(value) { _size.value = value }
39+
private var size = 0 // Invariant: size <= capacity
4440

4541
protected final override val isBufferAlwaysEmpty: Boolean get() = false
4642
protected final override val isBufferEmpty: Boolean get() = lock.withLock { size == 0 }
4743
protected final override val isBufferAlwaysFull: Boolean get() = false
48-
protected final override val isBufferFull: Boolean get() = size == capacity
44+
protected final override val isBufferFull: Boolean get() = lock.withLock { size == capacity }
4945

5046
// result is `OFFER_SUCCESS | OFFER_FAILED | Closed`
5147
protected override fun offerInternal(element: E): Any {

0 commit comments

Comments
 (0)