Commit 53573c02 authored by Dmitriy Vyukov's avatar Dmitriy Vyukov Committed by Andrew Gerrand

rpc: make Server.Mutex unexported

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