net/rpc: protect serviceMap with RWMutex

R=r, r
CC=golang-dev
https://golang.org/cl/6494044
This commit is contained in:
Dmitriy Vyukov 2012-08-30 20:32:32 +04:00
parent de13e8dccd
commit e61c047c3e

View File

@ -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