Skip to content
Snippets Groups Projects
Commit 944e6dc8 authored by xujianhai666's avatar xujianhai666
Browse files

add lock for invocation attachment

parent d65659ff
No related branches found
No related tags found
No related merge requests found
......@@ -19,6 +19,7 @@ package invocation
import (
"reflect"
"sync"
)
import (
......@@ -37,6 +38,7 @@ type RPCInvocation struct {
callBack interface{}
attachments map[string]string
invoker protocol.Invoker
lock sync.RWMutex
}
func NewRPCInvocation(methodName string, arguments []interface{}, attachments map[string]string) *RPCInvocation {
......@@ -80,6 +82,8 @@ func (r *RPCInvocation) Attachments() map[string]string {
}
func (r *RPCInvocation) AttachmentsByKey(key string, defaultValue string) string {
r.lock.RLock()
defer r.lock.RUnlock()
if r.attachments == nil {
return defaultValue
}
......@@ -91,6 +95,8 @@ func (r *RPCInvocation) AttachmentsByKey(key string, defaultValue string) string
}
func (r *RPCInvocation) SetAttachments(key string, value string) {
r.lock.Lock()
defer r.lock.Unlock()
if r.attachments == nil {
r.attachments = make(map[string]string)
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment