mirror of
https://github.com/DNSCrypt/dnscrypt-proxy.git
synced 2025-03-04 10:24:40 +01:00
Merge pull request #2541 from lifenjoiner/chan
Use blocking channel instead of looping sleep for less CPU usage
This commit is contained in:
commit
42b6ae9052
1 changed files with 6 additions and 3 deletions
|
@ -17,14 +17,13 @@ type CaptivePortalMap map[string]CaptivePortalEntryIPs
|
||||||
type CaptivePortalHandler struct {
|
type CaptivePortalHandler struct {
|
||||||
cancelChannel chan struct{}
|
cancelChannel chan struct{}
|
||||||
countChannel chan struct{}
|
countChannel chan struct{}
|
||||||
|
waitChannel chan struct{}
|
||||||
channelCount int
|
channelCount int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (captivePortalHandler *CaptivePortalHandler) Stop() {
|
func (captivePortalHandler *CaptivePortalHandler) Stop() {
|
||||||
close(captivePortalHandler.cancelChannel)
|
close(captivePortalHandler.cancelChannel)
|
||||||
for len(captivePortalHandler.countChannel) < captivePortalHandler.channelCount {
|
<-captivePortalHandler.waitChannel
|
||||||
time.Sleep(10 * time.Millisecond)
|
|
||||||
}
|
|
||||||
close(captivePortalHandler.countChannel)
|
close(captivePortalHandler.countChannel)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,6 +137,9 @@ func addColdStartListener(
|
||||||
}
|
}
|
||||||
clientPc.Close()
|
clientPc.Close()
|
||||||
captivePortalHandler.countChannel <- struct{}{}
|
captivePortalHandler.countChannel <- struct{}{}
|
||||||
|
if len(captivePortalHandler.countChannel) == captivePortalHandler.channelCount {
|
||||||
|
close(captivePortalHandler.waitChannel)
|
||||||
|
}
|
||||||
}()
|
}()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -186,6 +188,7 @@ func ColdStart(proxy *Proxy) (*CaptivePortalHandler, error) {
|
||||||
captivePortalHandler := CaptivePortalHandler{
|
captivePortalHandler := CaptivePortalHandler{
|
||||||
cancelChannel: make(chan struct{}),
|
cancelChannel: make(chan struct{}),
|
||||||
countChannel: make(chan struct{}, len(listenAddrStrs)),
|
countChannel: make(chan struct{}, len(listenAddrStrs)),
|
||||||
|
waitChannel: make(chan struct{}),
|
||||||
channelCount: 0,
|
channelCount: 0,
|
||||||
}
|
}
|
||||||
for _, listenAddrStr := range listenAddrStrs {
|
for _, listenAddrStr := range listenAddrStrs {
|
||||||
|
|
Loading…
Add table
Reference in a new issue