mirror of
https://github.com/WiiLink24/wfc-server.git
synced 2026-08-24 01:24:16 -05:00
Cache config, lock behind mutex
This commit is contained in:
@@ -3,6 +3,8 @@ package common
|
||||
import (
|
||||
"encoding/xml"
|
||||
"os"
|
||||
|
||||
"github.com/sasha-s/go-deadlock"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
@@ -48,10 +50,16 @@ type Config struct {
|
||||
ServerName string `xml:"serverName,omitempty"`
|
||||
}
|
||||
|
||||
var config Config
|
||||
var configLoaded bool
|
||||
var (
|
||||
config Config
|
||||
configLoaded bool
|
||||
cmutex = deadlock.Mutex{}
|
||||
)
|
||||
|
||||
func GetConfig() Config {
|
||||
cmutex.Lock()
|
||||
defer cmutex.Unlock()
|
||||
|
||||
if configLoaded {
|
||||
return config
|
||||
}
|
||||
@@ -128,5 +136,7 @@ func GetConfig() Config {
|
||||
config.AllowMultipleDeviceIDs = "never"
|
||||
}
|
||||
|
||||
configLoaded = true
|
||||
|
||||
return config
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user