Fix a deadlock in IpNeighbourMonitor
This commit is contained in:
@@ -3,10 +3,12 @@ package be.mygod.vpnhotspot.net.monitor
|
|||||||
import be.mygod.vpnhotspot.App.Companion.app
|
import be.mygod.vpnhotspot.App.Companion.app
|
||||||
import be.mygod.vpnhotspot.net.IpNeighbour
|
import be.mygod.vpnhotspot.net.IpNeighbour
|
||||||
import java.net.InetAddress
|
import java.net.InetAddress
|
||||||
|
import java.util.*
|
||||||
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
|
|
||||||
class IpNeighbourMonitor private constructor() : IpMonitor() {
|
class IpNeighbourMonitor private constructor() : IpMonitor() {
|
||||||
companion object {
|
companion object {
|
||||||
private val callbacks = HashSet<Callback>()
|
private val callbacks = Collections.newSetFromMap(ConcurrentHashMap<Callback, Boolean>())
|
||||||
var instance: IpNeighbourMonitor? = null
|
var instance: IpNeighbourMonitor? = null
|
||||||
|
|
||||||
fun registerCallback(callback: Callback) = synchronized(this) {
|
fun registerCallback(callback: Callback) = synchronized(this) {
|
||||||
@@ -65,10 +67,8 @@ class IpNeighbourMonitor private constructor() : IpMonitor() {
|
|||||||
updatePosted = false
|
updatePosted = false
|
||||||
neighbours.values.toList()
|
neighbours.values.toList()
|
||||||
}
|
}
|
||||||
synchronized(IpNeighbourMonitor) {
|
|
||||||
for (callback in callbacks) callback.onIpNeighbourAvailable(neighbours)
|
for (callback in callbacks) callback.onIpNeighbourAvailable(neighbours)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
updatePosted = true
|
updatePosted = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user