]> Cypherpunks repositories - gostls13.git/commitdiff
net/rpc: protect serviceMap with RWMutex
authorDmitriy Vyukov <dvyukov@google.com>
Thu, 30 Aug 2012 16:32:32 +0000 (20:32 +0400)
committerDmitriy Vyukov <dvyukov@google.com>
Thu, 30 Aug 2012 16:32:32 +0000 (20:32 +0400)
R=r, r
CC=golang-dev
https://golang.org/cl/6494044

src/pkg/net/rpc/server.go

index 9e0aa0ce2066d0079df6abe827729c6969bae083..e5282202c3d5e2cf78c55f115a016ee0b43cbbf8 100644 (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