From 26043bdefc159f49d7c9ca05d829033ed1c439c6 Mon Sep 17 00:00:00 2001 From: Mygod Date: Mon, 8 Oct 2018 12:59:38 +0800 Subject: [PATCH] Fix a deadlock in IpNeighbourMonitor --- .../be/mygod/vpnhotspot/net/monitor/IpNeighbourMonitor.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/IpNeighbourMonitor.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/IpNeighbourMonitor.kt index 2336f369..a9020afe 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/IpNeighbourMonitor.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/IpNeighbourMonitor.kt @@ -3,10 +3,12 @@ package be.mygod.vpnhotspot.net.monitor import be.mygod.vpnhotspot.App.Companion.app import be.mygod.vpnhotspot.net.IpNeighbour import java.net.InetAddress +import java.util.* +import java.util.concurrent.ConcurrentHashMap class IpNeighbourMonitor private constructor() : IpMonitor() { companion object { - private val callbacks = HashSet() + private val callbacks = Collections.newSetFromMap(ConcurrentHashMap()) var instance: IpNeighbourMonitor? = null fun registerCallback(callback: Callback) = synchronized(this) { @@ -65,9 +67,7 @@ class IpNeighbourMonitor private constructor() : IpMonitor() { updatePosted = false neighbours.values.toList() } - synchronized(IpNeighbourMonitor) { - for (callback in callbacks) callback.onIpNeighbourAvailable(neighbours) - } + for (callback in callbacks) callback.onIpNeighbourAvailable(neighbours) } updatePosted = true }