Partially lock setVehicle to void deadlock in applyAction (#3857)
This commit is contained in:
parent
7d12728ee6
commit
76a400ef1c
2 changed files with 14 additions and 2 deletions
|
|
@ -786,6 +786,9 @@ func (lp *LoadPoint) selectVehicleByID(id string) api.Vehicle {
|
|||
|
||||
// setActiveVehicle assigns currently active vehicle and configures soc estimator
|
||||
func (lp *LoadPoint) setActiveVehicle(vehicle api.Vehicle) {
|
||||
lp.Lock()
|
||||
defer lp.Unlock()
|
||||
|
||||
if lp.vehicle == vehicle {
|
||||
return
|
||||
}
|
||||
|
|
@ -809,6 +812,9 @@ func (lp *LoadPoint) setActiveVehicle(vehicle api.Vehicle) {
|
|||
lp.publish("vehicleTitle", lp.vehicle.Title())
|
||||
lp.publish("vehicleCapacity", lp.vehicle.Capacity())
|
||||
|
||||
// release lock to unblock api
|
||||
lp.Unlock()
|
||||
|
||||
// publish odometer once
|
||||
if vs, ok := lp.vehicle.(api.VehicleOdometer); ok {
|
||||
if odo, err := vs.Odometer(); err == nil {
|
||||
|
|
@ -821,6 +827,9 @@ func (lp *LoadPoint) setActiveVehicle(vehicle api.Vehicle) {
|
|||
|
||||
lp.applyAction(vehicle.OnIdentified())
|
||||
|
||||
// re-apply lock to match defer above
|
||||
lp.Lock()
|
||||
|
||||
lp.progress.Reset()
|
||||
} else {
|
||||
lp.socEstimator = nil
|
||||
|
|
|
|||
|
|
@ -266,12 +266,15 @@ func (lp *LoadPoint) GetVehicles() []api.Vehicle {
|
|||
|
||||
// SetVehicle sets the active vehicle
|
||||
func (lp *LoadPoint) SetVehicle(vehicle api.Vehicle) {
|
||||
lp.Lock()
|
||||
defer lp.Unlock()
|
||||
// TODO develop universal locking approach
|
||||
// setActiveVehicle is protected by lock, hence no locking here
|
||||
|
||||
// set desired vehicle
|
||||
lp.setActiveVehicle(vehicle)
|
||||
|
||||
lp.Lock()
|
||||
defer lp.Unlock()
|
||||
|
||||
// disable auto-detect
|
||||
lp.stopVehicleDetection()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue