goprotobuf: Replace an instance of sync.Mutex with a sync.RWMutex.
We can't change the sync.Mutex in properties.go
because it protects writes to the global stats var.
Fixes #21.
R=r
CC=golang-dev
http://codereview.appspot.com/5327059
diff --git a/proto/lib.go b/proto/lib.go
index 26d84ae..13e1753 100644
--- a/proto/lib.go
+++ b/proto/lib.go
@@ -558,9 +558,9 @@
func setDefaults(v reflect.Value, recur, zeros bool) {
v = v.Elem()
- defaultMu.Lock()
+ defaultMu.RLock()
dm, ok := defaults[v.Type()]
- defaultMu.Unlock()
+ defaultMu.RUnlock()
if !ok {
dm = buildDefaultMessage(v.Type())
defaultMu.Lock()
@@ -664,7 +664,7 @@
var (
// defaults maps a protocol buffer struct type to a slice of the fields,
// with its scalar fields set to their proto-declared non-zero default values.
- defaultMu sync.Mutex
+ defaultMu sync.RWMutex
defaults = make(map[reflect.Type]defaultMessage)
int32PtrType = reflect.TypeOf((*int32)(nil))