Browse Source

codec: rpc: remove unnecessary mutex Lock/Unlock during WriteXXX methods of codec

The net/rpc package states that the io.ReadWriteCloser should handle
concurrency if desired. This means that any required lock/unlock should be at the
implementation of io.ReadWriteCloser, not the codec.

Updates #271
Ugorji Nwoke 7 years ago
parent
commit
b30ce92d50
1 changed files with 1 additions and 8 deletions
  1. 1 8
      codec/rpc.go

+ 1 - 8
codec/rpc.go

@@ -8,7 +8,6 @@ import (
 	"errors"
 	"errors"
 	"io"
 	"io"
 	"net/rpc"
 	"net/rpc"
-	"sync"
 )
 )
 
 
 var errRpcJsonNeedsTermWhitespace = errors.New("rpc requires a JsonHandle with TermWhitespace set to true")
 var errRpcJsonNeedsTermWhitespace = errors.New("rpc requires a JsonHandle with TermWhitespace set to true")
@@ -40,8 +39,7 @@ type rpcCodec struct {
 	enc *Encoder
 	enc *Encoder
 	// bw  *bufio.Writer
 	// bw  *bufio.Writer
 	// br  *bufio.Reader
 	// br  *bufio.Reader
-	mu sync.Mutex
-	h  Handle
+	h Handle
 
 
 	cls atomicClsErr
 	cls atomicClsErr
 }
 }
@@ -160,15 +158,10 @@ type goRpcCodec struct {
 }
 }
 
 
 func (c *goRpcCodec) WriteRequest(r *rpc.Request, body interface{}) error {
 func (c *goRpcCodec) WriteRequest(r *rpc.Request, body interface{}) error {
-	// Must protect for concurrent access as per API
-	c.mu.Lock()
-	defer c.mu.Unlock()
 	return c.write(r, body, true)
 	return c.write(r, body, true)
 }
 }
 
 
 func (c *goRpcCodec) WriteResponse(r *rpc.Response, body interface{}) error {
 func (c *goRpcCodec) WriteResponse(r *rpc.Response, body interface{}) error {
-	c.mu.Lock()
-	defer c.mu.Unlock()
 	return c.write(r, body, true)
 	return c.write(r, body, true)
 }
 }