Skip to content

Commit 2ff5e4e

Browse files
committed
Calling a function containing atomic operations from a different file results in the failure of Native incremental compilation.
Made BufferedChannel#sendImpl function private. This is a WA for KT-65554
1 parent 761bdeb commit 2ff5e4e

File tree

2 files changed

+38
-38
lines changed

2 files changed

+38
-38
lines changed

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

+38-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ internal open class BufferedChannel<E>(
241241
/**
242242
* Abstract send implementation.
243243
*/
244-
protected inline fun <R> sendImpl(
244+
private inline fun <R> sendImpl(
245245
/* The element to be sent. */
246246
element: E,
247247
/* The waiter to be stored in case of suspension,
@@ -350,6 +350,43 @@ internal open class BufferedChannel<E>(
350350
}
351351
}
352352

353+
protected fun trySendDropLatest(element: E, isSendOp: Boolean): ChannelResult<Unit> {
354+
// Try to send the element without suspension.
355+
val result = trySend(element)
356+
// Complete on success or if this channel is closed.
357+
if (result.isSuccess || result.isClosed) return result
358+
// This channel is full. Drop the sending element.
359+
// Call the `onUndeliveredElement` lambda ONLY for 'send()' invocations,
360+
// for 'trySend()' it is responsibility of the caller
361+
if (isSendOp) {
362+
onUndeliveredElement?.callUndeliveredElementCatchingException(element)?.let {
363+
throw it
364+
}
365+
}
366+
return success(Unit)
367+
}
368+
369+
protected fun trySendDropOldest(element: E): ChannelResult<Unit> =
370+
sendImpl( // <-- this is an inline function
371+
element = element,
372+
// Put the element into the logical buffer even
373+
// if this channel is already full, the `onSuspend`
374+
// callback below extract the first (oldest) element.
375+
waiter = BUFFERED,
376+
// Finish successfully when a rendezvous has happened
377+
// or the element has been buffered.
378+
onRendezvousOrBuffered = { return success(Unit) },
379+
// In case the algorithm decided to suspend, the element
380+
// was added to the buffer. However, as the buffer is now
381+
// overflowed, the first (oldest) element has to be extracted.
382+
onSuspend = { segm, i ->
383+
dropFirstElementUntilTheSpecifiedCellIsInTheBuffer(segm.id * SEGMENT_SIZE + i)
384+
return success(Unit)
385+
},
386+
// If the channel is closed, return the corresponding result.
387+
onClosed = { return closed(sendException) }
388+
)
389+
353390
private inline fun sendImplOnNoWaiter(
354391
/* The working cell is specified by
355392
the segment and the index in it. */

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

-37
Original file line numberDiff line numberDiff line change
@@ -56,43 +56,6 @@ internal open class ConflatedBufferedChannel<E>(
5656
if (onBufferOverflow === DROP_LATEST) trySendDropLatest(element, isSendOp)
5757
else trySendDropOldest(element)
5858

59-
private fun trySendDropLatest(element: E, isSendOp: Boolean): ChannelResult<Unit> {
60-
// Try to send the element without suspension.
61-
val result = super.trySend(element)
62-
// Complete on success or if this channel is closed.
63-
if (result.isSuccess || result.isClosed) return result
64-
// This channel is full. Drop the sending element.
65-
// Call the `onUndeliveredElement` lambda ONLY for 'send()' invocations,
66-
// for 'trySend()' it is responsibility of the caller
67-
if (isSendOp) {
68-
onUndeliveredElement?.callUndeliveredElementCatchingException(element)?.let {
69-
throw it
70-
}
71-
}
72-
return success(Unit)
73-
}
74-
75-
private fun trySendDropOldest(element: E): ChannelResult<Unit> =
76-
sendImpl( // <-- this is an inline function
77-
element = element,
78-
// Put the element into the logical buffer even
79-
// if this channel is already full, the `onSuspend`
80-
// callback below extract the first (oldest) element.
81-
waiter = BUFFERED,
82-
// Finish successfully when a rendezvous has happened
83-
// or the element has been buffered.
84-
onRendezvousOrBuffered = { return success(Unit) },
85-
// In case the algorithm decided to suspend, the element
86-
// was added to the buffer. However, as the buffer is now
87-
// overflowed, the first (oldest) element has to be extracted.
88-
onSuspend = { segm, i ->
89-
dropFirstElementUntilTheSpecifiedCellIsInTheBuffer(segm.id * SEGMENT_SIZE + i)
90-
return success(Unit)
91-
},
92-
// If the channel is closed, return the corresponding result.
93-
onClosed = { return closed(sendException) }
94-
)
95-
9659
@Suppress("UNCHECKED_CAST")
9760
override fun registerSelectForSend(select: SelectInstance<*>, element: Any?) {
9861
// The plain `send(..)` operation never suspends. Thus, either this

0 commit comments

Comments
 (0)