diff options
Diffstat (limited to 'addMutex.go')
| -rw-r--r-- | addMutex.go | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/addMutex.go b/addMutex.go index cfd31b3..d0d8836 100644 --- a/addMutex.go +++ b/addMutex.go @@ -6,12 +6,29 @@ package main import ( "fmt" + "io" "os" "strings" "go.wit.com/log" ) +func (pf *File) syncLock(w io.Writer) { + var LOCK string = pf.Bases.Lockname + + fmt.Fprintln(w, "// a simple global lock") + fmt.Fprintln(w, "") + fmt.Fprintln(w, "// this is needed because it seems Marshal() fails if locks are in the structs (?)") + fmt.Fprintln(w, "// this might just be a syntactical runtime error. notsure.") + fmt.Fprintln(w, "// maybe this autogen tool will help someone that actually knows what is going on inside") + fmt.Fprintln(w, "// go/src/google.golang.org/protobuf/proto/proto_methods.go") + fmt.Fprintln(w, "// go/src/google.golang.org/protobuf/proto/encode.go") + fmt.Fprintln(w, "// my guess is that Marshal() needs to be told to ignore sync.RWMutex as it ephemeral and can't be stored") + fmt.Fprintln(w, "") + fmt.Fprintln(w, "var "+LOCK+" sync.RWMutex") + fmt.Fprintln(w, "") +} + func (pb *Files) addMutex(f *File) error { fullname := f.Pbfilename log.Info("pb filename:", fullname) @@ -47,7 +64,9 @@ func (pb *Files) addMutex(f *File) error { if argv.Mutex { log.Info("Adding Mutex to:", line) fmt.Fprintln(w, line) - fmt.Fprintln(w, "\tLock sync.RWMutex // auto-added by go.wit.com/apps/autogenpb") + fmt.Fprintln(w, "\tLock sync.RWMutex // auto-added by go.wit.com/apps/autogenpb") // this must be 'Lock' or Marshal() panics? + // fmt.Fprintln(w, "\t// auto-added by go.wit.com/apps/autogenpb") + // fmt.Fprintln(w, "\tsync.RWMutex") fmt.Fprintln(w, "") } else { log.Info("Skipping. Mutex = false for:", line) @@ -79,6 +98,12 @@ func (pf *File) structMatch(line string) bool { return true } + // ONLY PASS THIS IF YOU DO NOT WANT TO USE MARSHAL() + + if argv.Marshal { + return false + } + msg = pf.Base start = "type " + msg.Name + " struct {" if strings.HasPrefix(line, start) { |
