fix(*) pass pointers to share lock

Also lock the plugin when doing symbol lookup.
This commit is contained in:
Javier Guerra
2019-11-19 17:42:01 -05:00
committed by Guilherme Salazar
parent bff605d63c
commit b59c19779f
3 changed files with 12 additions and 8 deletions

View File

@@ -26,7 +26,7 @@ type eventData struct {
// mutated or holds references to mutable data.
//
// RPC exported method
func (s PluginServer) HandleEvent(in StartEventData, out *StepData) error {
func (s *PluginServer) HandleEvent(in StartEventData, out *StepData) error {
s.lock.RLock()
instance, ok := s.instances[in.InstanceId]
s.lock.RUnlock()
@@ -80,7 +80,7 @@ type StepData struct {
// the return value is either a new callback request or a finish signal.
//
// RPC exported method
func (s PluginServer) Step(in StepData, out *StepData) error {
func (s *PluginServer) Step(in StepData, out *StepData) error {
s.lock.RLock()
event, ok := s.events[in.EventId]
s.lock.RUnlock()

View File

@@ -93,7 +93,7 @@ func (s *PluginServer) StartInstance(config PluginConfig, status *InstanceStatus
// InstanceStatus returns a given resource's status (the same given when started)
//
// RPC exported method
func (s PluginServer) InstanceStatus(id int, status *InstanceStatus) error {
func (s *PluginServer) InstanceStatus(id int, status *InstanceStatus) error {
s.lock.RLock()
instance, ok := s.instances[id]
s.lock.RUnlock()
@@ -117,7 +117,7 @@ func (s PluginServer) InstanceStatus(id int, status *InstanceStatus) error {
// Returns the status just before closing.
//
// RPC exported method
func (s PluginServer) CloseInstance(id int, status *InstanceStatus) error {
func (s *PluginServer) CloseInstance(id int, status *InstanceStatus) error {
s.lock.RLock()
instance, ok := s.instances[id]
s.lock.RUnlock()

View File

@@ -45,17 +45,17 @@ func (s *PluginServer) SetPluginDir(dir string, reply *string) error {
// --- pluginData --- //
type pluginData struct {
lock sync.Mutex
name string
code *plugin.Plugin
constructor func() interface{}
config interface{}
}
func (s PluginServer) loadPlugin(name string) (plug *pluginData, err error) {
s.lock.Lock()
defer s.lock.Unlock()
func (s *PluginServer) loadPlugin(name string) (plug *pluginData, err error) {
s.lock.RLock()
plug, ok := s.plugins[name]
s.lock.RUnlock()
if ok {
return
}
@@ -85,7 +85,9 @@ func (s PluginServer) loadPlugin(name string) (plug *pluginData, err error) {
config: constructor(),
}
s.lock.Lock()
s.plugins[name] = plug
s.lock.Unlock()
return
}
@@ -166,6 +168,7 @@ func (s PluginServer) GetPluginInfo(name string, info *PluginInfo) error {
*info = PluginInfo{Name: name}
plug.lock.Lock()
handlers := getHandlers(plug.config)
info.Phases = make([]string, len(handlers))
@@ -194,6 +197,7 @@ func (s PluginServer) GetPluginInfo(name string, info *PluginInfo) error {
out.WriteString(st)
out.WriteString(`}}]}`)
plug.lock.Unlock()
info.Schema = out.String()