Skip to content

Commit

Permalink
Align synchronization declarations of runtime:runtime module with oth…
Browse files Browse the repository at this point in the history
…er compose modules (ui:ui, ui:ui-text, foundation:foundation)

- rename SynchronizedObject.kt to Synchronization.kt
- move it to androidx.compose.runtime.platform package
  • Loading branch information
pjBooms committed Oct 30, 2024
1 parent 71b6ad1 commit 062911a
Show file tree
Hide file tree
Showing 28 changed files with 91 additions and 37 deletions.
6 changes: 5 additions & 1 deletion compose/runtime/runtime/api/desktop/runtime.api
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public final class androidx/compose/runtime/ActualDesktop_desktopKt {

public final class androidx/compose/runtime/ActualJvm_jvmKt {
public static final fun identityHashCode (Ljava/lang/Object;)I
public static final fun synchronized (Landroidx/compose/runtime/SynchronizedObject;Lkotlin/jvm/functions/Function0;)Ljava/lang/Object;
public static final synthetic fun synchronized (Landroidx/compose/runtime/SynchronizedObject;Lkotlin/jvm/functions/Function0;)Ljava/lang/Object;
}

public abstract interface class androidx/compose/runtime/Applier {
Expand Down Expand Up @@ -904,6 +904,10 @@ public abstract interface annotation class androidx/compose/runtime/internal/Sta
public abstract fun parameters ()I
}

public final class androidx/compose/runtime/platform/Synchronization_desktopKt {
public static final fun synchronized (Landroidx/compose/runtime/SynchronizedObject;Lkotlin/jvm/functions/Function0;)Ljava/lang/Object;
}

public final class androidx/compose/runtime/reflect/ComposableMethod {
public static final field $stable I
public final fun asMethod ()Ljava/lang/reflect/Method;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2024 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.
*/

@file:JvmName("ActualJvm_jvmKt")
@file:JvmMultifileClass

package androidx.compose.runtime

import androidx.compose.runtime.platform.SynchronizedObject
import kotlin.DeprecationLevel.HIDDEN

@PublishedApi
@JvmName("synchronized")
@Deprecated(level = HIDDEN, message = "should not be used")
internal inline fun <R> oldSynchronized(lock: SynchronizedObject, block: () -> R): R =
androidx.compose.runtime.platform.synchronized(lock, block)
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@
* limitations under the License.
*/

@file:JvmName("ActualJvm_jvmKt")
@file:JvmMultifileClass

package androidx.compose.runtime
package androidx.compose.runtime.platform

@Suppress("ACTUAL_WITHOUT_EXPECT") // https://youtrack.jetbrains.com/issue/KT-37316
internal actual typealias SynchronizedObject = Any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package androidx.compose.runtime

import androidx.compose.runtime.internal.AtomicInt
import androidx.compose.runtime.platform.makeSynchronizedObject
import androidx.compose.runtime.platform.synchronized
import androidx.compose.runtime.snapshots.fastForEach
import kotlin.coroutines.Continuation
import kotlin.coroutines.resumeWithException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import androidx.compose.runtime.collection.fastForEach
import androidx.compose.runtime.internal.AtomicReference
import androidx.compose.runtime.internal.RememberEventDispatcher
import androidx.compose.runtime.internal.trace
import androidx.compose.runtime.platform.makeSynchronizedObject
import androidx.compose.runtime.platform.synchronized
import androidx.compose.runtime.snapshots.ReaderKind
import androidx.compose.runtime.snapshots.StateObjectImpl
import androidx.compose.runtime.snapshots.fastAll
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package androidx.compose.runtime

import androidx.compose.runtime.internal.PlatformOptimizedCancellationException
import androidx.compose.runtime.platform.makeSynchronizedObject
import androidx.compose.runtime.platform.synchronized
import kotlin.concurrent.Volatile
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package androidx.compose.runtime

import androidx.compose.runtime.platform.makeSynchronizedObject
import androidx.compose.runtime.platform.synchronized
import kotlin.coroutines.Continuation
import kotlin.coroutines.resume
import kotlinx.coroutines.suspendCancellableCoroutine
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import androidx.collection.emptyScatterSet
import androidx.collection.mutableIntListOf
import androidx.collection.mutableObjectListOf
import androidx.compose.runtime.internal.RememberEventDispatcher
import androidx.compose.runtime.platform.SynchronizedObject
import androidx.compose.runtime.platform.synchronized

/**
* A [PausableComposition] is a sub-composition that can be composed incrementally as it supports
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package androidx.compose.runtime
import androidx.collection.MutableObjectIntMap
import androidx.collection.MutableScatterMap
import androidx.collection.ScatterSet
import androidx.compose.runtime.platform.makeSynchronizedObject
import androidx.compose.runtime.platform.synchronized
import androidx.compose.runtime.snapshots.fastAny
import androidx.compose.runtime.snapshots.fastForEach
import androidx.compose.runtime.tooling.CompositionObserverHandle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ import androidx.compose.runtime.snapshots.fastMapNotNull
import androidx.compose.runtime.tooling.CompositionData
import kotlin.collections.removeFirst as removeFirstKt
import kotlin.collections.removeLast as removeLastKt
import androidx.compose.runtime.platform.SynchronizedObject
import androidx.compose.runtime.platform.makeSynchronizedObject
import androidx.compose.runtime.platform.synchronized
import kotlin.coroutines.Continuation
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package androidx.compose.runtime
import androidx.collection.MutableIntObjectMap
import androidx.collection.MutableIntSet
import androidx.collection.MutableObjectList
import androidx.compose.runtime.platform.makeSynchronizedObject
import androidx.compose.runtime.platform.synchronized
import androidx.compose.runtime.snapshots.fastAny
import androidx.compose.runtime.snapshots.fastFilterIndexed
import androidx.compose.runtime.snapshots.fastForEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

package androidx.compose.runtime.internal

import androidx.compose.runtime.makeSynchronizedObject
import androidx.compose.runtime.synchronized
import androidx.compose.runtime.platform.makeSynchronizedObject
import androidx.compose.runtime.platform.synchronized

/**
* This is similar to a [ThreadLocal] but has lower overhead because it avoids a weak reference.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package androidx.compose.runtime
package androidx.compose.runtime.platform

internal expect class SynchronizedObject

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ import androidx.compose.runtime.internal.AtomicReference
import androidx.compose.runtime.internal.JvmDefaultWithCompatibility
import androidx.compose.runtime.internal.SnapshotThreadLocal
import androidx.compose.runtime.internal.currentThreadId
import androidx.compose.runtime.makeSynchronizedObject
import androidx.compose.runtime.platform.makeSynchronizedObject
import androidx.compose.runtime.requirePrecondition
import androidx.compose.runtime.snapshots.Snapshot.Companion.takeMutableSnapshot
import androidx.compose.runtime.snapshots.Snapshot.Companion.takeSnapshot
import androidx.compose.runtime.snapshots.tooling.creatingSnapshot
import androidx.compose.runtime.snapshots.tooling.dispatchObserverOnApplied
import androidx.compose.runtime.snapshots.tooling.dispatchObserverOnDispose
import androidx.compose.runtime.synchronized
import androidx.compose.runtime.platform.synchronized
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ package androidx.compose.runtime.snapshots
import androidx.compose.runtime.Stable
import androidx.compose.runtime.external.kotlinx.collections.immutable.PersistentList
import androidx.compose.runtime.external.kotlinx.collections.immutable.persistentListOf
import androidx.compose.runtime.makeSynchronizedObject
import androidx.compose.runtime.platform.makeSynchronizedObject
import androidx.compose.runtime.requirePrecondition
import androidx.compose.runtime.synchronized
import androidx.compose.runtime.platform.synchronized
import kotlin.jvm.JvmName

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ package androidx.compose.runtime.snapshots
import androidx.compose.runtime.Stable
import androidx.compose.runtime.external.kotlinx.collections.immutable.PersistentMap
import androidx.compose.runtime.external.kotlinx.collections.immutable.persistentHashMapOf
import androidx.compose.runtime.makeSynchronizedObject
import androidx.compose.runtime.synchronized
import androidx.compose.runtime.platform.makeSynchronizedObject
import androidx.compose.runtime.platform.synchronized
import kotlin.jvm.JvmName

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ import androidx.compose.runtime.composeRuntimeError
import androidx.compose.runtime.internal.AtomicReference
import androidx.compose.runtime.internal.currentThreadId
import androidx.compose.runtime.internal.currentThreadName
import androidx.compose.runtime.makeSynchronizedObject
import androidx.compose.runtime.platform.makeSynchronizedObject
import androidx.compose.runtime.observeDerivedStateRecalculations
import androidx.compose.runtime.requirePrecondition
import androidx.compose.runtime.structuralEqualityPolicy
import androidx.compose.runtime.synchronized
import androidx.compose.runtime.platform.synchronized

/**
* Helper class to efficiently observe snapshot state reads. See [observeReads] for more details.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ package androidx.compose.runtime.snapshots
import androidx.compose.runtime.Stable
import androidx.compose.runtime.external.kotlinx.collections.immutable.PersistentSet
import androidx.compose.runtime.external.kotlinx.collections.immutable.persistentSetOf
import androidx.compose.runtime.makeSynchronizedObject
import androidx.compose.runtime.synchronized
import androidx.compose.runtime.platform.makeSynchronizedObject
import androidx.compose.runtime.platform.synchronized
import kotlin.jvm.JvmName

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
* limitations under the License.
*/

package androidx.compose.runtime
package androidx.compose.runtime.platform

internal actual val PTHREAD_MUTEX_ERRORCHECK: Int = platform.posix.PTHREAD_MUTEX_ERRORCHECK
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019 The Android Open Source Project
* Copyright 2024 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.
Expand All @@ -14,13 +14,20 @@
* limitations under the License.
*/

@file:JvmName("ActualJvm_jvmKt")
@file:JvmMultifileClass

package androidx.compose.runtime

import kotlin.DeprecationLevel.HIDDEN

// TODO https://youtrack.jetbrains.com/issue/CMP-719/Make-expect-fun-identityHashCodeinstance-Any-Int-internal
@InternalComposeApi
@Deprecated("Made internal. It wasn't supposed to be public")
fun identityHashCode(instance: Any?): Int =
androidx.compose.runtime.internal.identityHashCode(instance)
androidx.compose.runtime.internal.identityHashCode(instance)

internal class SynchronizedObject

@PublishedApi
@JvmName("synchronized")
@Deprecated(level = HIDDEN, message = "should not be used")
internal inline fun <R> oldSynchronized2(lock: SynchronizedObject, block: () -> R): R =
androidx.compose.runtime.platform.synchronized(lock, block)
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ import kotlin.DeprecationLevel.*

@PublishedApi
@JvmName("synchronized")
@Deprecated(level = HIDDEN, message = "Use SynchronizedObjectKt.synchronized() instead")
internal fun <R> oldSynchronized(lock: SynchronizedObject, block: () -> R): R = synchronized(lock, block)
@Deprecated(level = HIDDEN, message = "should not be used")
internal inline fun <R> oldSynchronized(lock: SynchronizedObject, block: () -> R): R =
androidx.compose.runtime.platform.synchronized(lock, block)
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package androidx.compose.runtime.platform

@file:JvmName("ActualJvm_jvmKt")
@file:JvmMultifileClass

package androidx.compose.runtime

internal actual class SynchronizedObject
@Suppress("ACTUAL_WITHOUT_EXPECT") // https://youtrack.jetbrains.com/issue/KT-37316
internal actual typealias SynchronizedObject = androidx.compose.runtime.SynchronizedObject

@Suppress("NOTHING_TO_INLINE")
internal actual inline fun makeSynchronizedObject(ref: Any?) = SynchronizedObject()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
* limitations under the License.
*/

package androidx.compose.runtime
package androidx.compose.runtime.platform

internal actual val PTHREAD_MUTEX_ERRORCHECK: Int = platform.posix.PTHREAD_MUTEX_ERRORCHECK.toInt()
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package androidx.compose.runtime
package androidx.compose.runtime.platform

import androidx.compose.runtime.internal.currentThreadId
import kotlinx.atomicfu.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package androidx.compose.runtime
package androidx.compose.runtime.platform

import kotlin.concurrent.AtomicInt
import kotlin.native.concurrent.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import androidx.compose.runtime.mock.ViewApplier
import androidx.compose.runtime.mock.compositionTest
import androidx.compose.runtime.mock.validate
import androidx.compose.runtime.mock.view
import androidx.compose.runtime.platform.SynchronizedObject
import androidx.compose.runtime.platform.synchronized
import kotlin.coroutines.resume
import kotlin.test.Ignore
import kotlin.test.Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package androidx.compose.runtime
package androidx.compose.runtime.platform

import androidx.compose.runtime.internal.currentThreadId
import kotlin.native.ref.createCleaner
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package androidx.compose.runtime
package androidx.compose.runtime.platform

internal actual class SynchronizedObject

Expand Down

0 comments on commit 062911a

Please sign in to comment.