Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8558d846 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes I00ef363a,Iee1a219f into main

* changes:
  [kairos] Fix indirectRoot set change tracking
  [kairos] Remove unused mutex
parents 8e7a11cb ce0fa6cf
Loading
Loading
Loading
Loading
+1 −5
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ import com.android.systemui.kairos.internal.store.MapK
import com.android.systemui.kairos.internal.store.MutableMapK
import com.android.systemui.kairos.internal.util.hashString
import com.android.systemui.kairos.internal.util.logDuration
import kotlinx.coroutines.sync.Mutex

internal class DemuxNode<W, K, A>(
    private val branchNodeByKey: MutableMapK<W, K, DemuxNode<W, K, A>.BranchNode>,
@@ -138,7 +137,6 @@ internal class DemuxNode<W, K, A>(
        branchNodeByKey.remove(key)
        val deactivate = branchNodeByKey.isEmpty()
        if (deactivate) {
            // No need for mutex here; no more concurrent changes to can occur during this phase
            lifecycle.lifecycleState = DemuxLifecycleState.Inactive(spec)
            upstreamConnection.removeDownstreamAndDeactivateIfNeeded(downstream = schedulable)
        }
@@ -259,9 +257,7 @@ internal class DemuxImpl<in K, out A>(private val dmux: DemuxLifecycle<K, A>) {
}

internal class DemuxLifecycle<K, A>(@Volatile var lifecycleState: DemuxLifecycleState<K, A>) {
    val mutex = Mutex()

    override fun toString(): String = "EventsDmuxState[$hashString][$lifecycleState][$mutex]"
    override fun toString(): String = "EventsDmuxState[$hashString][$lifecycleState]"

    fun activate(evalScope: EvalScope, key: K): Pair<DemuxNode<*, K, A>.BranchNode, Boolean>? =
        when (val state = lifecycleState) {
+7 −5
Original line number Diff line number Diff line
@@ -166,15 +166,17 @@ internal class DepthTracker {
        val addsChanged =
            additions
                ?.let { dirty_indirectUpstreamRoots.addAll(additions, butNot) }
                ?.let {
                    indirectAdditions.addAll(indirectRemovals.applyRemovalDiff(it))
                ?.let { newlyAdded ->
                    val remainder = indirectRemovals.applyRemovalDiff(newlyAdded)
                    indirectAdditions.addAll(remainder)
                    true
                } ?: false
        val removalsChanged =
            removals
                ?.let { dirty_indirectUpstreamRoots.removeAll(removals) }
                ?.let {
                    indirectRemovals.addAll(indirectAdditions.applyRemovalDiff(it))
                ?.let { fullyRemoved ->
                    val remainder = indirectAdditions.applyRemovalDiff(fullyRemoved)
                    indirectRemovals.addAll(remainder)
                    true
                } ?: false
        return (!dirty_depthIsDirect && (addsChanged || removalsChanged))
@@ -183,7 +185,7 @@ internal class DepthTracker {
    private fun <T> HashSet<T>.applyRemovalDiff(changeSet: Set<T>): Set<T> {
        val remainder = HashSet<T>()
        for (element in changeSet) {
            if (!add(element)) {
            if (!remove(element)) {
                remainder.add(element)
            }
        }
+8 −0
Original line number Diff line number Diff line
@@ -51,6 +51,10 @@ internal class Bag<T> private constructor(private val intMap: MutableMap<T, Int>
        }
    }

    /**
     * Adds all [elements], skipping [butNot], and returns the subset of [elements] that were not
     * already present in this bag.
     */
    fun addAll(elements: Iterable<T>, butNot: T? = null): Set<T>? {
        val newlyAdded = hashSetOf<T>()
        for (value in elements) {
@@ -67,6 +71,10 @@ internal class Bag<T> private constructor(private val intMap: MutableMap<T, Int>
        intMap.clear()
    }

    /**
     * Removes all [elements], and returns the subset of [elements] that are no longer present in
     * this bag.
     */
    fun removeAll(elements: Collection<T>): Set<T>? {
        val result = hashSetOf<T>()
        for (element in elements) {