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. // mutated or holds references to mutable data.
// //
// RPC exported method // RPC exported method
func (s PluginServer) HandleEvent(in StartEventData, out *StepData) error { func (s *PluginServer) HandleEvent(in StartEventData, out *StepData) error {
s.lock.RLock() s.lock.RLock()
instance, ok := s.instances[in.InstanceId] instance, ok := s.instances[in.InstanceId]
s.lock.RUnlock() s.lock.RUnlock()
@@ -80,7 +80,7 @@ type StepData struct {
// the return value is either a new callback request or a finish signal. // the return value is either a new callback request or a finish signal.
// //
// RPC exported method // RPC exported method
func (s PluginServer) Step(in StepData, out *StepData) error { func (s *PluginServer) Step(in StepData, out *StepData) error {
s.lock.RLock() s.lock.RLock()
event, ok := s.events[in.EventId] event, ok := s.events[in.EventId]
s.lock.RUnlock() 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) // InstanceStatus returns a given resource's status (the same given when started)
// //
// RPC exported method // RPC exported method
func (s PluginServer) InstanceStatus(id int, status *InstanceStatus) error { func (s *PluginServer) InstanceStatus(id int, status *InstanceStatus) error {
s.lock.RLock() s.lock.RLock()
instance, ok := s.instances[id] instance, ok := s.instances[id]
s.lock.RUnlock() s.lock.RUnlock()
@@ -117,7 +117,7 @@ func (s PluginServer) InstanceStatus(id int, status *InstanceStatus) error {
// Returns the status just before closing. // Returns the status just before closing.
// //
// RPC exported method // RPC exported method
func (s PluginServer) CloseInstance(id int, status *InstanceStatus) error { func (s *PluginServer) CloseInstance(id int, status *InstanceStatus) error {
s.lock.RLock() s.lock.RLock()
instance, ok := s.instances[id] instance, ok := s.instances[id]
s.lock.RUnlock() s.lock.RUnlock()

View File

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