synchronized access to hashmap
This commit is contained in:
parent
70db735476
commit
1f9f112f68
1 changed files with 4 additions and 2 deletions
|
@ -130,8 +130,10 @@ class StoreDataForDbImpl @Inject constructor(
|
||||||
private val pause = 1000L // to slow down db operations
|
private val pause = 1000L // to slow down db operations
|
||||||
|
|
||||||
fun <T> HashMap<T, Long>.inc(key: T) =
|
fun <T> HashMap<T, Long>.inc(key: T) =
|
||||||
|
synchronized(this) {
|
||||||
if (containsKey(key)) merge(key, 1, Long::plus)
|
if (containsKey(key)) merge(key, 1, Long::plus)
|
||||||
else put(key, 1)
|
else put(key, 1)
|
||||||
|
}
|
||||||
|
|
||||||
override fun storeGlucoseValuesToDb() {
|
override fun storeGlucoseValuesToDb() {
|
||||||
if (glucoseValues.isNotEmpty())
|
if (glucoseValues.isNotEmpty())
|
||||||
|
|
Loading…
Reference in a new issue