chore: fix potential deadlock
This commit is contained in:
parent
d64871c33a
commit
bff27c9fbc
1 changed files with 4 additions and 2 deletions
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue