Skip to content

Commit

Permalink
Remove synchronization between GlobalSnapshotManager and ComposeScene…
Browse files Browse the repository at this point in the history
….postponeInvalidation (#546)

# Conflicts:
#	compose/ui/ui/src/skikoMain/kotlin/androidx/compose/ui/ComposeScene.skiko.kt
  • Loading branch information
m-sasha authored and igordmn committed Jun 8, 2023
1 parent a8c7fe3 commit 68901d6
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package androidx.compose.ui.platform

import androidx.compose.runtime.snapshots.Snapshot
import androidx.compose.ui.platform.GlobalSnapshotManager.ensureStarted
import androidx.compose.ui.createSynchronizedObject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.channels.consumeEach
Expand All @@ -37,7 +36,6 @@ import kotlinx.coroutines.Dispatchers
* may establish different policies for these notifications.
*/
internal actual object GlobalSnapshotManager {
internal actual val sync = createSynchronizedObject()
private val started = AtomicInt(0)

actual fun ensureStarted() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ package androidx.compose.ui.platform

import androidx.compose.runtime.snapshots.Snapshot
import androidx.compose.ui.platform.GlobalSnapshotManager.ensureStarted
import androidx.compose.ui.createSynchronizedObject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.channels.consumeEach
import kotlinx.coroutines.launch
Expand All @@ -39,19 +37,14 @@ import java.util.concurrent.atomic.AtomicBoolean
* may establish different policies for these notifications.
*/
internal actual object GlobalSnapshotManager {
internal actual val sync = createSynchronizedObject()
private val started = AtomicBoolean(false)

actual fun ensureStarted() {
if (started.compareAndSet(false, true)) {
val channel = Channel<Unit>(Channel.CONFLATED)
Dispatchers.IO
CoroutineScope(MainUIDispatcher).launch {
channel.consumeEach {
// TODO(https://github.com/JetBrains/compose-jb/issues/1854) get rid of synchronized
synchronized(sync) {
Snapshot.sendApplyNotifications()
}
Snapshot.sendApplyNotifications()
}
}
Snapshot.registerGlobalWriteObserver {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package androidx.compose.ui.platform

import androidx.compose.runtime.snapshots.Snapshot
import androidx.compose.ui.platform.GlobalSnapshotManager.ensureStarted
import androidx.compose.ui.createSynchronizedObject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.channels.Channel
Expand All @@ -37,7 +36,6 @@ import kotlinx.coroutines.launch
* may establish different policies for these notifications.
*/
internal actual object GlobalSnapshotManager {
internal actual val sync = createSynchronizedObject()
private val started = AtomicInt(0)

actual fun ensureStarted() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

package androidx.compose.ui.platform

import androidx.compose.ui.SynchronizedObject

/**
* Platform-specific mechanism for starting a monitor of global snapshot state writes
* in order to schedule the periodic dispatch of snapshot apply notifications.
Expand All @@ -26,10 +24,7 @@ import androidx.compose.ui.SynchronizedObject
*
* Composition bootstrapping mechanisms for a particular platform/framework should call
* [ensureStarted] during setup to initialize periodic global snapshot notifications.
* For desktop, these notifications are always sent on [MainUIDispatcher]. Other platforms
* may establish different policies for these notifications.
*/
internal expect object GlobalSnapshotManager {
internal val sync: SynchronizedObject
fun ensureStarted()
}

0 comments on commit 68901d6

Please sign in to comment.