summaryrefslogtreecommitdiff
path: root/generateMutex.go
diff options
context:
space:
mode:
Diffstat (limited to 'generateMutex.go')
-rw-r--r--generateMutex.go22
1 files changed, 18 insertions, 4 deletions
diff --git a/generateMutex.go b/generateMutex.go
index 45d0d2e..790816b 100644
--- a/generateMutex.go
+++ b/generateMutex.go
@@ -13,8 +13,19 @@ import (
"go.wit.com/log"
)
+func (msg *MsgName) getLockname(s string) string {
+ // leave this function stubbed in for development of autogenpb
+ // if argv.Mutex {
+ // // use the mutex lock from the modified protoc.pb.go file
+ // return s + ".Lock"
+ // // return s // causes Marshal() to panic? always use the variable name 'Lock'?
+ // }
+ // a single global lock by struct name
+ return msg.Lockname
+}
+
func (pf *File) syncLock(w io.Writer) {
- var LOCK string = pf.Base.Lockname // if the Marshall code changes, this will have to change
+ var LOCK string = pf.Filebase + "Mu" // this should be lowercase. do not export the Mutex
fmt.Fprintln(w, "// a simple global lock")
fmt.Fprintln(w, "var "+LOCK+" sync.RWMutex")
@@ -110,7 +121,6 @@ func (pf *File) structMatch(line string) bool {
start = "type " + msg.Name + " struct {"
if strings.HasPrefix(line, start) {
msg.MutexFound = true
- msg.Lockname = "x.Lock"
return true
}
@@ -120,7 +130,7 @@ func (pf *File) structMatch(line string) bool {
start = "type " + msg.Name + " struct {"
if strings.HasPrefix(line, start) {
msg.MutexFound = true
- // msg.Lockname = "x.Lock"
+ msg.Lockname = "x.Lock"
return true
}
@@ -128,7 +138,11 @@ func (pf *File) structMatch(line string) bool {
start = "type " + msg.Name + " struct {"
if strings.HasPrefix(line, start) {
msg.MutexFound = true
- // msg.Lockname = "x.Lock"
+ if msg.NoMutex {
+ msg.Lockname = pf.Filebase + "Mu" // this should be lowercase. do not export the Mutex
+ } else {
+ msg.Lockname = "x.Lock"
+ }
return true
}
}