diff options
| author | Jeff Carr <[email protected]> | 2025-01-12 08:28:23 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-01-12 08:28:23 -0600 |
| commit | 10f75f87a66a9329fd665bd85099fe94c7beae79 (patch) | |
| tree | 5746e3e18d3bdf3d8213798436ee93d0dd052772 /generateMutex.go | |
| parent | 721bbd8f92d80286f12509fbbcff9f2f8e334093 (diff) | |
add nomutex support to disable it per message struct
Diffstat (limited to 'generateMutex.go')
| -rw-r--r-- | generateMutex.go | 22 |
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 } } |
