* move "controlLock" mutex to "config"

This commit is contained in:
Simon Zolin 2019-07-09 18:25:26 +03:00
parent d51f43e27a
commit 2682adca39
5 changed files with 9 additions and 11 deletions

View File

@ -53,6 +53,7 @@ type configuration struct {
disableUpdate bool // If set, don't check for updates
appSignalChannel chan os.Signal
clients clientsContainer
controlLock sync.Mutex
BindHost string `yaml:"bind_host"` // BindHost is the IP address of the HTTP server to bind to
BindPort int `yaml:"bind_port"` // BindPort is the port the HTTP server

View File

@ -11,7 +11,6 @@ import (
"sort"
"strconv"
"strings"
"sync"
"time"
"github.com/AdguardTeam/AdGuardHome/dnsforward"
@ -40,8 +39,6 @@ var client = &http.Client{
Transport: transport,
}
var controlLock sync.Mutex
// ----------------
// helper functions
// ----------------

View File

@ -17,13 +17,13 @@ type accessListJSON struct {
func handleAccessList(w http.ResponseWriter, r *http.Request) {
log.Tracef("%s %v", r.Method, r.URL)
controlLock.Lock()
config.controlLock.Lock()
j := accessListJSON{
AllowedClients: config.DNS.AllowedClients,
DisallowedClients: config.DNS.DisallowedClients,
BlockedHosts: config.DNS.BlockedHosts,
}
controlLock.Unlock()
config.controlLock.Unlock()
w.Header().Set("Content-Type", "application/json")
err := json.NewEncoder(w).Encode(j)

View File

@ -73,10 +73,10 @@ func handleGetVersionJSON(w http.ResponseWriter, r *http.Request) {
now := time.Now()
if !req.RecheckNow {
controlLock.Lock()
config.controlLock.Lock()
cached := now.Sub(versionCheckLastTime) <= versionCheckPeriod && len(versionCheckJSON) != 0
data := versionCheckJSON
controlLock.Unlock()
config.controlLock.Unlock()
if cached {
log.Tracef("Returning cached data")
@ -103,10 +103,10 @@ func handleGetVersionJSON(w http.ResponseWriter, r *http.Request) {
return
}
controlLock.Lock()
config.controlLock.Lock()
versionCheckLastTime = now
versionCheckJSON = body
controlLock.Unlock()
config.controlLock.Unlock()
w.Header().Set("Content-Type", "application/json")
_, err = w.Write(getVersionResp(body))

View File

@ -35,8 +35,8 @@ func ensure(method string, handler func(http.ResponseWriter, *http.Request)) fun
}
if method == "POST" || method == "PUT" || method == "DELETE" {
controlLock.Lock()
defer controlLock.Unlock()
config.controlLock.Lock()
defer config.controlLock.Unlock()
}
handler(w, r)