@@ -250,8 +250,14 @@ private class StateFlowSlot : AbstractSharedFlowSlot<StateFlowImpl<*>>() {
250
250
*
251
251
* It is important that default `null` value is used, because there can be a race between allocation
252
252
* of a new slot and trying to do [makePending] on this slot.
253
+ *
254
+ * ===
255
+ * This should be `atomic<Any?>(null)` instead of the atomic reference, but because of #3820
256
+ * it is used as a **temporary** solution starting from 1.8.1 version.
257
+ * Depending on the fix rollout on Android, it will be removed in 1.9.0 or 2.0.0.
258
+ * See https://issuetracker.google.com/issues/325123736
253
259
*/
254
- private val _state = atomic <Any ?>(null )
260
+ private val _state = WorkaroundAtomicReference <Any ?>(null )
255
261
256
262
override fun allocateLocked (flow : StateFlowImpl <* >): Boolean {
257
263
// No need for atomic check & update here, since allocated happens under StateFlow lock
@@ -290,7 +296,6 @@ private class StateFlowSlot : AbstractSharedFlowSlot<StateFlowImpl<*>>() {
290
296
return state == = PENDING
291
297
}
292
298
293
- @Suppress(" UNCHECKED_CAST" )
294
299
suspend fun awaitPending (): Unit = suspendCancellableCoroutine sc@ { cont ->
295
300
assert { _state .value !is CancellableContinuationImpl <* > } // can be NONE or PENDING
296
301
if (_state .compareAndSet(NONE , cont)) return @sc // installed continuation, waiting for pending
@@ -306,7 +311,6 @@ private class StateFlowImpl<T>(
306
311
private val _state = atomic(initialState) // T | NULL
307
312
private var sequence = 0 // serializes updates, value update is in process when sequence is odd
308
313
309
- @Suppress(" UNCHECKED_CAST" )
310
314
public override var value: T
311
315
get() = NULL .unbox(_state .value)
312
316
set(value) { updateState(null , value ? : NULL ) }
0 commit comments