11package com.powersync.db
22
33import co.touchlab.kermit.Logger
4- import kotlinx.atomicfu.atomic
5- import kotlinx.atomicfu.locks.SynchronizedObject
6- import kotlinx.atomicfu.locks.synchronized
4+ import co.touchlab.stately.concurrency.AtomicBoolean
5+ import co.touchlab.stately.concurrency.Synchronizable
6+ import co.touchlab.stately.concurrency.synchronize
77import kotlinx.coroutines.sync.Mutex
88
99/* *
@@ -27,14 +27,14 @@ internal class ActiveDatabaseGroup(
2727 internal val syncMutex = Mutex ()
2828
2929 fun removeUsage () {
30- synchronized( ActiveDatabaseGroup ) {
30+ ActiveDatabaseGroup .synchronize {
3131 if (-- refCount == 0 ) {
3232 allGroups.remove(this )
3333 }
3434 }
3535 }
3636
37- companion object : SynchronizedObject () {
37+ companion object : Synchronizable () {
3838 internal val multipleInstancesMessage =
3939 """
4040 Multiple PowerSync instances for the same database have been detected.
@@ -47,8 +47,7 @@ internal class ActiveDatabaseGroup(
4747 private fun findGroup (
4848 warnOnDuplicate : Logger ,
4949 identifier : String ,
50- ): ActiveDatabaseGroup =
51- synchronized(this ) {
50+ ): ActiveDatabaseGroup = synchronize {
5251 val existing = allGroups.asSequence().firstOrNull { it.identifier == identifier }
5352 val resolvedGroup =
5453 if (existing == null ) {
@@ -81,10 +80,10 @@ internal class ActiveDatabaseGroup(
8180internal class ActiveDatabaseResource (
8281 val group : ActiveDatabaseGroup ,
8382) {
84- val disposed = atomic (false )
83+ val disposed = AtomicBoolean (false )
8584
8685 fun dispose () {
87- if (! disposed.getAndSet( true )) {
86+ if (disposed.compareAndSet( false , true )) {
8887 group.removeUsage()
8988 }
9089 }
0 commit comments