mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-11-13 15:16:56 +01:00
adds a mutex to make sure memory clearing only happens once at a time.
This commit is contained in:
@@ -71,6 +71,7 @@ import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
|
||||
@Stable
|
||||
class ServiceManager(
|
||||
@@ -84,6 +85,8 @@ class ServiceManager(
|
||||
|
||||
private var collectorJob: Job? = null
|
||||
|
||||
var isTrimmingMemoryMutex = AtomicBoolean(false)
|
||||
|
||||
private fun start(account: Account) {
|
||||
this.account = account
|
||||
start()
|
||||
@@ -259,6 +262,8 @@ class ServiceManager(
|
||||
}
|
||||
|
||||
suspend fun trimMemory() {
|
||||
if (isTrimmingMemoryMutex.compareAndSet(false, true)) {
|
||||
try {
|
||||
LocalCache.cleanObservers()
|
||||
|
||||
val accounts =
|
||||
@@ -274,6 +279,10 @@ class ServiceManager(
|
||||
LocalCache.prunePastVersionsOfReplaceables()
|
||||
LocalCache.pruneExpiredEvents()
|
||||
}
|
||||
} finally {
|
||||
isTrimmingMemoryMutex.getAndSet(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This method keeps the pause/start in a Syncronized block to
|
||||
|
||||
Reference in New Issue
Block a user