]> Cypherpunks repositories - gostls13.git/commitdiff
rpc: make Server.Mutex unexported
authorDmitriy Vyukov <dvyukov@google.com>
Tue, 16 Aug 2011 08:34:56 +0000 (18:34 +1000)
committerAndrew Gerrand <adg@golang.org>
Tue, 16 Aug 2011 08:34:56 +0000 (18:34 +1000)
Currently it's possible to write:
var s rpc.Server
...
// reuse for my own purposes
s.Lock()
...
s.Unlock()
which is seemingly not intended.

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/4888049

src/pkg/rpc/debug.go
src/pkg/rpc/server.go

index ae76a4586ad504538e93b8e55fca275061b5f508..80d20641531785398448a49344be0cbbeda2efc5 100644 (file)
@@ -70,7 +70,7 @@ func (server debugHTTP) ServeHTTP(w http.ResponseWriter, req *http.Request) {
        // Build a sorted version of the data.
        var services = make(serviceArray, len(server.serviceMap))
        i := 0
-       server.Lock()
+       server.mu.Lock()
        for sname, service := range server.serviceMap {
                services[i] = debugService{service, sname, make(methodArray, len(service.method))}
                j := 0
@@ -81,7 +81,7 @@ func (server debugHTTP) ServeHTTP(w http.ResponseWriter, req *http.Request) {
                sort.Sort(services[i].Method)
                i++
        }
-       server.Unlock()
+       server.mu.Unlock()
        sort.Sort(services)
        err := debug.Execute(w, services)
        if err != nil {
index ac3f793047db1bfbe08c4cfe483cd235fcd392c7..74507442862326d561bff71a86ceedac3f3f0905 100644 (file)
@@ -174,7 +174,7 @@ type Response struct {
 
 // Server represents an RPC Server.
 type Server struct {
-       sync.Mutex // protects the serviceMap
+       mu         sync.Mutex // protects the serviceMap
        serviceMap map[string]*service
        reqLock    sync.Mutex // protects freeReq
        freeReq    *Request
@@ -226,8 +226,8 @@ func (server *Server) RegisterName(name string, rcvr interface{}) os.Error {
 }
 
 func (server *Server) register(rcvr interface{}, name string, useName bool) os.Error {
-       server.Lock()
-       defer server.Unlock()
+       server.mu.Lock()
+       defer server.mu.Unlock()
        if server.serviceMap == nil {
                server.serviceMap = make(map[string]*service)
        }
@@ -524,9 +524,9 @@ func (server *Server) readRequestHeader(codec ServerCodec) (service *service, mt
                return
        }
        // Look up the request.
-       server.Lock()
+       server.mu.Lock()
        service = server.serviceMap[serviceMethod[0]]
-       server.Unlock()
+       server.mu.Unlock()
        if service == nil {
                err = os.NewError("rpc: can't find service " + req.ServiceMethod)
                return