safe data for continues
This commit is contained in:
parent
ed53d1bae7
commit
dd98f656d1
|
@ -3,6 +3,7 @@ package respondd
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/FreifunkBremen/yanic/data"
|
"github.com/FreifunkBremen/yanic/data"
|
||||||
"github.com/FreifunkBremen/yanic/lib/duration"
|
"github.com/FreifunkBremen/yanic/lib/duration"
|
||||||
|
@ -26,6 +27,7 @@ type Daemon struct {
|
||||||
Babel string `toml:"babel"`
|
Babel string `toml:"babel"`
|
||||||
babelData *babelState.BabelState `toml:"-"`
|
babelData *babelState.BabelState `toml:"-"`
|
||||||
|
|
||||||
|
dataMX sync.Mutex
|
||||||
dataByInterface map[string]*data.ResponseData
|
dataByInterface map[string]*data.ResponseData
|
||||||
|
|
||||||
Answer *AnswerConfig `toml:"defaults"`
|
Answer *AnswerConfig `toml:"defaults"`
|
||||||
|
|
|
@ -22,6 +22,8 @@ func (d *Daemon) updateData() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Daemon) getData(iface string) *data.ResponseData {
|
func (d *Daemon) getData(iface string) *data.ResponseData {
|
||||||
|
d.dataMX.Lock()
|
||||||
|
defer d.dataMX.Unlock()
|
||||||
if iData, ok := d.dataByInterface[iface]; ok {
|
if iData, ok := d.dataByInterface[iface]; ok {
|
||||||
return iData
|
return iData
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,9 @@ func (d *Daemon) Start() {
|
||||||
d.AnswerByZones = make(map[string]*AnswerConfig)
|
d.AnswerByZones = make(map[string]*AnswerConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
d.dataMX.Lock()
|
||||||
d.updateData()
|
d.updateData()
|
||||||
|
d.dataMX.Unlock()
|
||||||
go d.updateWorker()
|
go d.updateWorker()
|
||||||
|
|
||||||
if d.Babel != "" {
|
if d.Babel != "" {
|
||||||
|
@ -69,6 +71,8 @@ func (d *Daemon) updateWorker() {
|
||||||
c := time.Tick(d.DataInterval.Duration)
|
c := time.Tick(d.DataInterval.Duration)
|
||||||
|
|
||||||
for range c {
|
for range c {
|
||||||
|
d.dataMX.Lock()
|
||||||
d.updateData()
|
d.updateData()
|
||||||
|
d.dataMX.Unlock()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue