Skip to content

Commit

Permalink
Adding mutex to extpointHandlers
Browse files Browse the repository at this point in the history
Handlers may be registered during daemon start, not just package init,
so we have to protect the map with a mutex as well.

Signed-off-by: Jeff Lindsay <progrium@gmail.com>
  • Loading branch information
progrium committed May 8, 2015
1 parent 9a4d310 commit 203405b
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions plugins/plugins.go
Expand Up @@ -9,14 +9,19 @@ import (

var (
activePlugins = &plugins{plugins: make(map[string]*Plugin)}
extpointHandlers = make(map[string]func(string, *Client))
extpointHandlers = &handlers{handlers: make(map[string]func(string, *Client))}
)

type plugins struct {
sync.Mutex
plugins map[string]*Plugin
}

type handlers struct {
sync.Mutex
handlers map[string]func(string, *Client)
}

type Manifest struct {
Implements []string
}
Expand Down Expand Up @@ -44,8 +49,11 @@ func (p *Plugin) Activate() error {
}
p.Manifest = m

extpointHandlers.Lock()
defer extpointHandlers.Unlock()

for _, iface := range m.Implements {
handler, handled := extpointHandlers[iface]
handler, handled := extpointHandlers.handlers[iface]
if !handled {
continue
}
Expand Down Expand Up @@ -103,5 +111,7 @@ func Active() []*Plugin {
}

func Handle(iface string, fn func(string, *Client)) {
extpointHandlers[iface] = fn
extpointHandlers.Lock()
defer extpointHandlers.Unlock()
extpointHandlers.handlers[iface] = fn
}

0 comments on commit 203405b

Please sign in to comment.