Skip to content

Commit

Permalink
Reapply "chore: fix potential deadlock"
Browse files Browse the repository at this point in the history
This reverts commit 6116e8c.
  • Loading branch information
andig committed Aug 18, 2024
1 parent ac5e686 commit d74fbd3
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions util/config/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,18 @@ func (cp *handler[T]) Add(dev Device[T]) error {

// Delete deletes device
func (cp *handler[T]) Delete(name string) error {
cp.mu.RLock()
defer cp.mu.RUnlock()
cp.mu.Lock()

for i, dev := range cp.devices {
if name == dev.Config().Name {
cp.devices = append(cp.devices[:i], cp.devices[i+1:]...)
cp.mu.Unlock()

bus.Publish(cp.topic, OpDelete, dev)
return nil
}
}
cp.mu.Unlock()

return fmt.Errorf("not found: %s", name)
}
Expand Down

0 comments on commit d74fbd3

Please sign in to comment.