summaryrefslogtreecommitdiff
path: root/addMutex.go
diff options
context:
space:
mode:
Diffstat (limited to 'addMutex.go')
-rw-r--r--addMutex.go20
1 files changed, 16 insertions, 4 deletions
diff --git a/addMutex.go b/addMutex.go
index dfb091c..f9e143e 100644
--- a/addMutex.go
+++ b/addMutex.go
@@ -48,7 +48,10 @@ func (pb *Files) addMutex(f *File) error {
w, _ := os.OpenFile(f.Pbfilename, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
- pbHeaderComment(w)
+ // the default is to insert a mutex directly into the struct
+ if argv.Mutex {
+ pbHeaderComment(w)
+ }
lines := strings.Split(string(data), "\n")
for _, line := range lines {
@@ -59,6 +62,12 @@ func (pb *Files) addMutex(f *File) error {
// fmt.Fprintln(w, "package "+"main")
continue
}
+ // the default is to insert a mutex directly into the struct
+ if !argv.Mutex {
+ // mutex is not to be added, only fix the package name
+ fmt.Fprintln(w, line)
+ continue
+ }
if f.structMatch(line) {
if argv.Mutex {
@@ -78,9 +87,12 @@ func (pb *Files) addMutex(f *File) error {
fmt.Fprintln(w, line)
}
}
- for _, msg := range f.MsgNames {
- if !msg.MutexFound && msg.DoMutex {
- return fmt.Errorf("addMutex() parse didn't work for %s", msg.Name)
+ if argv.Mutex {
+ // verify every structure was found
+ for _, msg := range f.MsgNames {
+ if !msg.MutexFound && msg.DoMutex {
+ return fmt.Errorf("addMutex() parse didn't work for %s", msg.Name)
+ }
}
}
return nil