Lil adjustments to delegate syncher

This commit is contained in:
DBotThePony 2024-05-31 10:44:35 +07:00
parent 1f6eb023ed
commit cea53ec35e
Signed by: DBot
GPG Key ID: DCC23B5715498507
2 changed files with 13 additions and 10 deletions

View File

@ -4,7 +4,7 @@ kotlin.code.style=official
specifyKotlinAsDependency=false specifyKotlinAsDependency=false
projectGroup=ru.dbotthepony.kommons projectGroup=ru.dbotthepony.kommons
projectVersion=3.0.0 projectVersion=3.0.1
guavaDepVersion=33.0.0 guavaDepVersion=33.0.0
gsonDepVersion=2.8.9 gsonDepVersion=2.8.9

View File

@ -39,7 +39,7 @@ import kotlin.concurrent.withLock
* Values and delegates can be attached using [add], or by constructing subclassed directly. * Values and delegates can be attached using [add], or by constructing subclassed directly.
* Delta changes are tracked by [DelegateSyncher.Remote] instances. * Delta changes are tracked by [DelegateSyncher.Remote] instances.
* *
* In general, this class is not meant to be concurrently mutated by different threads, * In general, this class is not meant to be _structurally_ concurrently mutated by different threads,
* to avoid structure corruption a lock is employed. * to avoid structure corruption a lock is employed.
* *
* Attached delegates can be safely mutated by multiple threads concurrently * Attached delegates can be safely mutated by multiple threads concurrently
@ -630,7 +630,8 @@ class DelegateSyncher : Observer {
* To get changes to be networked to remote client, [write] should be called. * To get changes to be networked to remote client, [write] should be called.
*/ */
inner class Remote : Closeable { inner class Remote : Closeable {
private val isRemoved = AtomicBoolean() @Volatile
private var isRemoved = false
internal val dirty = ConcurrentLinkedQueue<RemoteSlot>() internal val dirty = ConcurrentLinkedQueue<RemoteSlot>()
private val remoteSlots = CopyOnWriteArrayList<RemoteSlot>() private val remoteSlots = CopyOnWriteArrayList<RemoteSlot>()
@ -647,7 +648,7 @@ class DelegateSyncher : Observer {
} }
fun markDirty() { fun markDirty() {
if (!isRemoved.get() && isDirty.compareAndSet(false, true)) { if (!isRemoved && isDirty.compareAndSet(false, true)) {
dirty.add(this) dirty.add(this)
} }
} }
@ -819,8 +820,9 @@ class DelegateSyncher : Observer {
} }
override fun close() { override fun close() {
if (isRemoved.compareAndSet(false, true)) { if (!isRemoved) {
lock.withLock { lock.withLock {
if (!isRemoved) {
remoteSlots.forEach { remoteSlots.forEach {
it.remove() it.remove()
it.parent.remoteSlots.remove(it) it.parent.remoteSlots.remove(it)
@ -828,6 +830,7 @@ class DelegateSyncher : Observer {
remotes.remove(this) remotes.remove(this)
} }
}
dirty.clear() dirty.clear()
} }