Fix potential deadlock
This commit is contained in:
parent
b41bf78909
commit
b970df81d8
2 changed files with 11 additions and 3 deletions
|
|
@ -171,7 +171,7 @@ func (lp *LoadPoint) SetMode(mode api.ChargeMode) {
|
|||
if lp.Mode != mode {
|
||||
lp.Mode = mode
|
||||
lp.publish("mode", mode)
|
||||
lp.lpChan <- lp // request loadpoint update
|
||||
lp.requestUpdate()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -193,7 +193,15 @@ func (lp *LoadPoint) SetTargetSoC(targetSoC int) {
|
|||
if lp.TargetSoC != targetSoC {
|
||||
lp.TargetSoC = targetSoC
|
||||
lp.publish("targetSoC", targetSoC)
|
||||
lp.lpChan <- lp // request loadpoint update
|
||||
lp.requestUpdate()
|
||||
}
|
||||
}
|
||||
|
||||
// requestUpdate requests site to update this loadpoint
|
||||
func (lp *LoadPoint) requestUpdate() {
|
||||
select {
|
||||
case lp.lpChan <- lp: // request loadpoint update
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -314,7 +314,7 @@ func (site *Site) update(lp Updater) {
|
|||
// Prepare attaches communication channels to site and loadpoints
|
||||
func (site *Site) Prepare(uiChan chan<- util.Param, pushChan chan<- push.Event) {
|
||||
site.uiChan = uiChan
|
||||
site.lpUpdateChan = make(chan *LoadPoint)
|
||||
site.lpUpdateChan = make(chan *LoadPoint, 1) // 1 capacity to avoid deadlock
|
||||
|
||||
for id, lp := range site.loadpoints {
|
||||
lpUIChan := make(chan util.Param)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue