@@ -12,7 +12,6 @@ import kotlin.coroutines.*
12
12
import kotlin.js.*
13
13
import kotlin.jvm.*
14
14
import kotlin.math.*
15
- import kotlin.native.concurrent.*
16
15
import kotlin.random.*
17
16
import kotlin.reflect.*
18
17
@@ -1236,7 +1235,6 @@ internal open class BufferedChannel<E>(
1236
1235
segm = segm.next ? : break
1237
1236
}
1238
1237
while (true ) {
1239
- val segmPrev = segm.prev
1240
1238
for (i in SEGMENT_SIZE - 1 downTo 0 ) {
1241
1239
if (segm.id * SEGMENT_SIZE + i < receivers.value) return
1242
1240
while (true ) {
@@ -1256,12 +1254,18 @@ internal open class BufferedChannel<E>(
1256
1254
}
1257
1255
state is Waiter -> {
1258
1256
if (segm.casState(i, state, CHANNEL_CLOSED )) {
1257
+ // if (onUndeliveredElement != null) {
1258
+ // undeliveredElementException = onUndeliveredElement.callUndeliveredElementCatchingException(segm.retrieveElement(i), undeliveredElementException)
1259
+ // }
1259
1260
state.closeSender()
1260
1261
break
1261
1262
}
1262
1263
}
1263
1264
state is WaiterEB -> {
1264
1265
if (segm.casState(i, state, CHANNEL_CLOSED )) {
1266
+ // if (onUndeliveredElement != null) {
1267
+ // undeliveredElementException = onUndeliveredElement.callUndeliveredElementCatchingException(segm.retrieveElement(i), undeliveredElementException)
1268
+ // }
1265
1269
state.waiter.closeSender()
1266
1270
break
1267
1271
}
@@ -1270,7 +1274,7 @@ internal open class BufferedChannel<E>(
1270
1274
}
1271
1275
}
1272
1276
}
1273
- segm = segmPrev ? : break
1277
+ segm = segm.prev ? : break
1274
1278
}
1275
1279
undeliveredElementException?.let { throw it } // throw UndeliveredElementException at the end if there was one
1276
1280
}
@@ -1306,7 +1310,7 @@ internal open class BufferedChannel<E>(
1306
1310
}
1307
1311
}
1308
1312
1309
- private fun Any .closeReceiver () = closeWaiter(receiver = true )
1313
+ private fun Waiter .closeReceiver () = closeWaiter(receiver = true )
1310
1314
private fun Any.closeSender () = closeWaiter(receiver = false )
1311
1315
1312
1316
private fun Any.closeWaiter (receiver : Boolean ): Boolean {
@@ -1757,7 +1761,8 @@ internal class ChannelSegment<E>(id: Long, prev: ChannelSegment<E>?, pointers: I
1757
1761
val update = when {
1758
1762
cur is Waiter -> INTERRUPTED
1759
1763
cur is WaiterEB -> INTERRUPTED_EB
1760
- cur == = S_RESUMING_EB || cur == = S_RESUMING_RCV -> continue
1764
+ cur == = S_RESUMING_EB -> continue
1765
+ cur == = S_RESUMING_RCV -> continue
1761
1766
cur == = INTERRUPTED_SEND -> INTERRUPTED_SEND
1762
1767
cur == = DONE || cur == = BUFFERED || cur == = CHANNEL_CLOSED -> return
1763
1768
else -> error(" unexpected: $cur " )
@@ -1773,7 +1778,6 @@ internal class ChannelSegment<E>(id: Long, prev: ChannelSegment<E>?, pointers: I
1773
1778
}
1774
1779
}
1775
1780
private fun <E > createSegment (id : Long , prev : ChannelSegment <E >? ) = ChannelSegment (id, prev, 0 )
1776
- @SharedImmutable
1777
1781
private val NULL_SEGMENT = createSegment<Any ?>(- 1 , null )
1778
1782
/* *
1779
1783
* Number of cells in each segment.
@@ -1816,41 +1820,33 @@ private fun initialBufferEnd(capacity: Int): Long = when (capacity) {
1816
1820
*/
1817
1821
1818
1822
// The cell stores a buffered element.
1819
- @SharedImmutable
1820
1823
private val BUFFERED = Symbol (" BUFFERED" )
1821
1824
// Concurrent `expandBuffer(..)` can inform the
1822
1825
// upcoming sender that it should buffer the element.
1823
- @SharedImmutable
1824
1826
private val IN_BUFFER = Symbol (" SHOULD_BUFFER" )
1825
1827
// Indicates that a receiver (R suffix) is resuming
1826
1828
// the suspended sender; after that, it should update
1827
1829
// the state to either `DONE` (on success) or
1828
1830
// `INTERRUPTED_R` (on failure).
1829
- @SharedImmutable
1830
1831
private val S_RESUMING_RCV = Symbol (" RESUMING_R" )
1831
1832
// Indicates that `expandBuffer(..)` is resuming the
1832
1833
// suspended sender; after that, it should update the
1833
1834
// state to either `BUFFERED` (on success) or
1834
1835
// `INTERRUPTED_EB` (on failure).
1835
- @SharedImmutable
1836
1836
private val S_RESUMING_EB = Symbol (" RESUMING_EB" )
1837
1837
// When a receiver comes to the cell already covered by
1838
1838
// a sender (according to the counters), but the cell
1839
1839
// is still in `EMPTY` or `IN_BUFFER` state, it poisons
1840
1840
// the cell by changing its state to `POISONED`.
1841
- @SharedImmutable
1842
1841
private val POISONED = Symbol (" POISONED" )
1843
1842
// When the element is successfully transferred (possibly,
1844
1843
// through buffering), the cell moves to `DONE` state.
1845
- @SharedImmutable
1846
1844
private val DONE = Symbol (" DONE" )
1847
1845
// When the waiter is cancelled, it moves the cell to
1848
1846
// `INTERRUPTED` state; thus, informing other parties
1849
1847
// that may come to the cell and avoiding memory leaks.
1850
- @SharedImmutable
1851
1848
private val INTERRUPTED = Symbol (" INTERRUPTED" )
1852
1849
// TODO
1853
- @SharedImmutable
1854
1850
private val INTERRUPTED_SEND = Symbol (" INTERRUPTED_SEND" )
1855
1851
// When the cell is already covered by both sender and
1856
1852
// receiver (`sender` and `receivers` counters are greater
@@ -1872,11 +1868,9 @@ private class WaiterEB(@JvmField val waiter: Waiter) {
1872
1868
// receiver that it should complete the `expandBuffer(..)`
1873
1869
// procedure if the cancelled waiter stored in the cell
1874
1870
// was sender.
1875
- @SharedImmutable
1876
1871
private val INTERRUPTED_EB = Symbol (" INTERRUPTED_EB" )
1877
1872
// Indicates that the channel is already closed,
1878
1873
// and no more operation should not touch this cell.
1879
- @SharedImmutable
1880
1874
internal val CHANNEL_CLOSED = Symbol (" CHANNEL_CLOSED" )
1881
1875
1882
1876
@@ -1895,11 +1889,8 @@ private class ReceiveCatching<E>(
1895
1889
buffered element retrieval, the corresponding element
1896
1890
is returned as result of [BufferedChannel.updateCellReceive].
1897
1891
*/
1898
- @SharedImmutable
1899
1892
private val SUSPEND = Symbol (" SUSPEND" )
1900
- @SharedImmutable
1901
1893
private val SUSPEND_NO_WAITER = Symbol (" SUSPEND_NO_WAITER" )
1902
- @SharedImmutable
1903
1894
private val FAILED = Symbol (" FAILED" )
1904
1895
1905
1896
/*
@@ -1915,7 +1906,6 @@ private const val RESULT_FAILED = 4
1915
1906
* Special value for [BufferedChannel.BufferedChannelIterator.receiveResult]
1916
1907
* that indicates the absence of pre-received result.
1917
1908
*/
1918
- @SharedImmutable
1919
1909
private val NO_RECEIVE_RESULT = Symbol (" NO_RECEIVE_RESULT" )
1920
1910
1921
1911
@@ -1962,23 +1952,19 @@ private inline fun constructSendersAndCloseStatus(counter: Long, closeStatus: In
1962
1952
+------------>| CLOSED |
1963
1953
close +--------+
1964
1954
*/
1965
- @SharedImmutable
1966
1955
private val CLOSE_HANDLER_CLOSED = Symbol (" CLOSE_HANDLER_CLOSED" )
1967
- @SharedImmutable
1968
1956
private val CLOSE_HANDLER_INVOKED = Symbol (" CLOSE_HANDLER_INVOKED" )
1969
1957
1970
1958
/* *
1971
1959
* Specifies the absence of closing cause, stored in [BufferedChannel.closeCause].
1972
1960
* When the channel is closed or cancelled without exception, this [NO_CLOSE_CAUSE]
1973
1961
* marker should be replaced with `null`.
1974
1962
*/
1975
- @SharedImmutable
1976
1963
private val NO_CLOSE_CAUSE = Symbol (" NO_CLOSE_CAUSE" )
1977
1964
1978
1965
/* *
1979
1966
* All waiters, such as [CancellableContinuationImpl], [SelectInstance], and
1980
1967
* [BufferedChannel.BufferedChannelIterator], should be marked with this interface
1981
1968
* to make the code faster and easier to read.
1982
1969
*/
1983
- @InternalCoroutinesApi
1984
1970
internal interface Waiter
0 commit comments