summaryrefslogtreecommitdiff
path: root/generateMutex.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-01-13 03:36:55 -0600
committerJeff Carr <[email protected]>2025-01-13 03:36:55 -0600
commitf74f3641879416068de07c4c10051b5e987a1e8d (patch)
treebe0f317862f66566aba65b1963d605326dd33afb /generateMutex.go
parent9cb5064906e54f999ba5ef0bf402901e0f7a5d5e (diff)
bad message handling logic. working the issue
Diffstat (limited to 'generateMutex.go')
-rw-r--r--generateMutex.go31
1 files changed, 19 insertions, 12 deletions
diff --git a/generateMutex.go b/generateMutex.go
index 0361895..9695cb1 100644
--- a/generateMutex.go
+++ b/generateMutex.go
@@ -14,6 +14,10 @@ import (
)
func (msg *MsgName) getLockname(s string) string {
+ if msg.NoMutex {
+ return "bad"
+ // return msg.Lockname
+ }
// leave this function stubbed in for development of autogenpb
// if argv.Mutex {
// // use the mutex lock from the modified protoc.pb.go file
@@ -120,8 +124,7 @@ func (pf *File) structMatch(line string) bool {
msg = pf.Bases
start = "type " + msg.Name + " struct {"
if strings.HasPrefix(line, start) {
- msg.MutexFound = true
- return true
+ return msg.setupMutex(pf.Filebase + "Mu")
}
// ONLY PASS THIS IF YOU DO NOT WANT TO USE MARSHAL()
@@ -129,22 +132,26 @@ func (pf *File) structMatch(line string) bool {
msg = pf.Base
start = "type " + msg.Name + " struct {"
if strings.HasPrefix(line, start) {
- msg.MutexFound = true
- msg.Lockname = "x.Lock"
- return true
+ return msg.setupMutex(pf.Filebase + "Mu")
}
for _, msg = range pf.MsgNames {
start = "type " + msg.Name + " struct {"
if strings.HasPrefix(line, start) {
- msg.MutexFound = true
- if msg.NoMutex {
- msg.Lockname = pf.Filebase + "Mu" // this should be lowercase. do not export the Mutex
- } else {
- msg.Lockname = "x.Lock"
- }
- return true
+ return msg.setupMutex(pf.Filebase + "Mu")
}
}
return false
}
+
+// nameMu should probably be lowercase.
+// notsure if it ever makes sense to export a mutex or even if you can
+func (msg *MsgName) setupMutex(nameMu string) bool {
+ msg.MutexFound = true
+ if msg.NoMutex {
+ msg.Lockname = nameMu
+ return false
+ }
+ msg.Lockname = "x.Lock"
+ return true
+}