Skip to content

Commit

Permalink
make the ping process Thread-safe
Browse files Browse the repository at this point in the history
  • Loading branch information
mcfans committed Jun 9, 2017
1 parent 158af9f commit 5e4d07e
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions ShadowsocksX-NG/PingClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,23 +144,25 @@ class PingServers:NSObject{
if let latency = $0{
self.SerMgr.profiles[k].latency = String(latency)

synchronized(lock: result as AnyObject){
result.append(k,latency)
}
DispatchQueue.main.async {
// do the UI update HERE
(NSApplication.shared().delegate as! AppDelegate).updateServersMenu()
(NSApplication.shared().delegate as! AppDelegate).updateRunningModeMenu()
}
}



})
}
// after two seconds ,time out
delay(3){
DispatchQueue.main.async {

for k in 0..<self.SerMgr.profiles.count {
if let late = self.SerMgr.profiles[k].latency{
if let latency = Double(late){
result.append((k,latency))
}
}
}


(NSApplication.shared().delegate as! AppDelegate).updateServersMenu()
(NSApplication.shared().delegate as! AppDelegate).updateRunningModeMenu()

// do the UI update HERE
if let min = result.min(by: {$0.1 < $1.1}){
self.fastest = String(describing: min.1)
Expand Down

0 comments on commit 5e4d07e

Please sign in to comment.