From: Dmitriy Vyukov Date: Fri, 21 Sep 2012 19:54:52 +0000 (+1000) Subject: [release-branch.go1] net/rpc: protect serviceMap with RWMutex X-Git-Tag: go1.0.3~60 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=94403eb5d36af8852ce500a249970d184db6ff01;p=gostls13.git [release-branch.go1] net/rpc: protect serviceMap with RWMutex ««« backport fa3b2ef0129d net/rpc: protect serviceMap with RWMutex R=r, r CC=golang-dev https://golang.org/cl/6494044 »»» --- diff --git a/src/pkg/net/rpc/server.go b/src/pkg/net/rpc/server.go index 9e0aa0ce20..e5282202c3 100644 --- a/src/pkg/net/rpc/server.go +++ b/src/pkg/net/rpc/server.go @@ -182,7 +182,7 @@ type Response struct { // Server represents an RPC Server. type Server struct { - mu sync.Mutex // protects the serviceMap + mu sync.RWMutex // protects the serviceMap serviceMap map[string]*service reqLock sync.Mutex // protects freeReq freeReq *Request @@ -539,9 +539,9 @@ func (server *Server) readRequestHeader(codec ServerCodec) (service *service, mt return } // Look up the request. - server.mu.Lock() + server.mu.RLock() service = server.serviceMap[serviceMethod[0]] - server.mu.Unlock() + server.mu.RUnlock() if service == nil { err = errors.New("rpc: can't find service " + req.ServiceMethod) return