-
-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: compose ios concurrent modification fix for 1.9 (#249)
- Loading branch information
1 parent
acad7f0
commit e78f6a6
Showing
7 changed files
with
110 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
.../src/nativeMain/kotlin/cafe.adriel.voyager.core/concurrent/ThreadSafeMutableCollection.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package cafe.adriel.voyager.core.concurrent | ||
|
||
import kotlinx.atomicfu.locks.SynchronizedObject | ||
import kotlinx.atomicfu.locks.synchronized | ||
|
||
public open class ThreadSafeMutableCollection<T>internal constructor( | ||
private val syncObject: SynchronizedObject, | ||
private val delegate: MutableCollection<T> | ||
) : MutableCollection<T> { | ||
|
||
override val size: Int | ||
get() = synchronized(syncObject) { delegate.size } | ||
|
||
override fun contains(element: T): Boolean { | ||
return synchronized(syncObject) { delegate.contains(element) } | ||
} | ||
|
||
override fun containsAll(elements: Collection<T>): Boolean { | ||
return synchronized(syncObject) { delegate.containsAll(elements) } | ||
} | ||
|
||
override fun isEmpty(): Boolean { | ||
return synchronized(syncObject) { delegate.isEmpty() } | ||
} | ||
|
||
override fun iterator(): MutableIterator<T> { | ||
return synchronized(syncObject) { ThreadSafeMutableIterator(syncObject, delegate.iterator()) } | ||
} | ||
|
||
override fun add(element: T): Boolean { | ||
return synchronized(syncObject) { delegate.add(element) } | ||
} | ||
|
||
override fun addAll(elements: Collection<T>): Boolean { | ||
return synchronized(syncObject) { delegate.addAll(elements) } | ||
} | ||
|
||
override fun clear() { | ||
return synchronized(syncObject) { delegate.clear() } | ||
} | ||
|
||
override fun remove(element: T): Boolean { | ||
return synchronized(syncObject) { delegate.remove(element) } | ||
} | ||
|
||
override fun removeAll(elements: Collection<T>): Boolean { | ||
return synchronized(syncObject) { delegate.removeAll(elements) } | ||
} | ||
|
||
override fun retainAll(elements: Collection<T>): Boolean { | ||
return synchronized(syncObject) { delegate.retainAll(elements) } | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...re/src/nativeMain/kotlin/cafe.adriel.voyager.core/concurrent/ThreadSafeMutableIterator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package cafe.adriel.voyager.core.concurrent | ||
|
||
import kotlinx.atomicfu.locks.SynchronizedObject | ||
import kotlinx.atomicfu.locks.synchronized | ||
|
||
internal open class ThreadSafeMutableIterator<E>( | ||
private val syncObject: SynchronizedObject, | ||
private val delegate: MutableIterator<E> | ||
) : MutableIterator<E> { | ||
override fun hasNext(): Boolean = synchronized(syncObject) { delegate.hasNext() } | ||
|
||
override fun next(): E = synchronized(syncObject) { delegate.next() } | ||
|
||
override fun remove() { | ||
synchronized(syncObject) { delegate.remove() } | ||
} | ||
} | ||
|
||
internal class ThreadSafeMutableListIterator<E>( | ||
private val syncObject: SynchronizedObject, | ||
private val delegate: MutableListIterator<E> | ||
) : ThreadSafeMutableIterator<E>(syncObject, delegate), | ||
MutableListIterator<E> { | ||
|
||
override fun hasPrevious(): Boolean = synchronized(syncObject) { delegate.hasPrevious() } | ||
|
||
override fun nextIndex(): Int = synchronized(syncObject) { delegate.nextIndex() } | ||
|
||
override fun previous(): E = synchronized(syncObject) { delegate.previous() } | ||
|
||
override fun previousIndex(): Int = synchronized(syncObject) { delegate.previousIndex() } | ||
|
||
override fun add(element: E) { | ||
synchronized(syncObject) { delegate.add(element) } | ||
} | ||
|
||
override fun set(element: E) { | ||
synchronized(syncObject) { delegate.set(element) } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters