1
1
package com.powersync.db
2
2
3
3
import 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
7
7
import kotlinx.coroutines.sync.Mutex
8
8
9
9
/* *
@@ -27,14 +27,14 @@ internal class ActiveDatabaseGroup(
27
27
internal val syncMutex = Mutex ()
28
28
29
29
fun removeUsage () {
30
- synchronized( ActiveDatabaseGroup ) {
30
+ ActiveDatabaseGroup .synchronize {
31
31
if (-- refCount == 0 ) {
32
32
allGroups.remove(this )
33
33
}
34
34
}
35
35
}
36
36
37
- companion object : SynchronizedObject () {
37
+ companion object : Synchronizable () {
38
38
internal val multipleInstancesMessage =
39
39
"""
40
40
Multiple PowerSync instances for the same database have been detected.
@@ -47,8 +47,7 @@ internal class ActiveDatabaseGroup(
47
47
private fun findGroup (
48
48
warnOnDuplicate : Logger ,
49
49
identifier : String ,
50
- ): ActiveDatabaseGroup =
51
- synchronized(this ) {
50
+ ): ActiveDatabaseGroup = synchronize {
52
51
val existing = allGroups.asSequence().firstOrNull { it.identifier == identifier }
53
52
val resolvedGroup =
54
53
if (existing == null ) {
@@ -81,10 +80,10 @@ internal class ActiveDatabaseGroup(
81
80
internal class ActiveDatabaseResource (
82
81
val group : ActiveDatabaseGroup ,
83
82
) {
84
- val disposed = atomic (false )
83
+ val disposed = AtomicBoolean (false )
85
84
86
85
fun dispose () {
87
- if (! disposed.getAndSet( true )) {
86
+ if (disposed.compareAndSet( false , true )) {
88
87
group.removeUsage()
89
88
}
90
89
}
0 commit comments