Skip to content

Commit

Permalink
Merge pull request moby#8 from progrium/handler_mutex
Browse files Browse the repository at this point in the history
Adding mutex to extpointHandlers
  • Loading branch information
calavera committed May 8, 2015
2 parents 9a4d310 + 203405b commit d7a3d76
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 d7a3d76

Please sign in to comment.