Skip to content

Commit

Permalink
Revert "Use Compose AtomicReference instead of `InternalAtomicRefer…
Browse files Browse the repository at this point in the history
…ence` in `InternalMutatorMutex`"

This reverts commit b95a5ab.
  • Loading branch information
msasikanth committed Sep 11, 2023
1 parent eaa0d5d commit a79cc6f
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dev.sasikanth.rss.reader.components.bottomsheet

import java.util.concurrent.atomic.AtomicReference

internal actual typealias InternalAtomicReference<V> = AtomicReference<V>
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package dev.sasikanth.rss.reader.components.bottomsheet

import androidx.compose.foundation.AtomicReference
import androidx.compose.foundation.MutatePriority
import androidx.compose.runtime.Stable
import kotlinx.coroutines.CancellationException
Expand All @@ -24,6 +23,18 @@ import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock

/**
* This is an internal copy of androidx.compose.foundation.MutatorMutex with an additional tryMutate
* method. Do not modify, except for tryMutate. **
*/
expect class InternalAtomicReference<V>(value: V) {
fun get(): V

fun set(value: V)

fun compareAndSet(expect: V, newValue: V): Boolean
}

/**
* Mutual exclusion for UI state mutation over time.
*
Expand All @@ -46,7 +57,7 @@ internal class InternalMutatorMutex {
fun cancel() = job.cancel()
}

private val currentMutator = AtomicReference<Mutator?>(null)
private val currentMutator = InternalAtomicReference<Mutator?>(null)
private val mutex = Mutex()

private fun tryMutateOrCancel(mutator: Mutator) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2023 Sasikanth Miriyampalli
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dev.sasikanth.rss.reader.components.bottomsheet

import kotlin.native.concurrent.AtomicReference

actual class InternalAtomicReference<V> actual constructor(value: V) {

private val atomicReference = AtomicReference(value)

actual fun get(): V {
return atomicReference.value
}

actual fun set(value: V) {
atomicReference.value = value
}

actual fun compareAndSet(expect: V, newValue: V): Boolean {
return atomicReference.compareAndSet(expect, newValue)
}
}

0 comments on commit a79cc6f

Please sign in to comment.