trying to get Mutex back to a working state
This commit is contained in:
parent
51a326c5d7
commit
3f2909aa0d
6
Makefile
6
Makefile
|
@ -1,8 +1,6 @@
|
|||
VERSION = $(shell git describe --tags)
|
||||
BUILDTIME = $(shell date +%Y.%m.%d_%H%M)
|
||||
|
||||
hmm: test
|
||||
|
||||
simple: build
|
||||
# make -C example clean simpleMutexGlobal goimports vet
|
||||
make -C example clean simpleMutexProtoc goimports vet
|
||||
|
@ -42,8 +40,10 @@ auto:
|
|||
# rm -f auto.sort.pb.go auto.newsort.pb.go # auto.marshal.pb.go
|
||||
|
||||
test:
|
||||
make -C example modproto
|
||||
make -C example rawproto
|
||||
# The Go Protocol Buffers library embeds a sync.Mutex within the MessageState struct to prevent unintended shallow copies of message structs
|
||||
# It only fails in Marshal() functions though. That is dumb.
|
||||
make -C example modproto # THIS DOES NOT WORK. It could work however. This autogenerated code could be used to debug it.
|
||||
|
||||
junk:
|
||||
cd example; rm -f go.* *.pb.go
|
||||
|
|
27
addMutex.go
27
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) {
|
||||
|
|
1
argv.go
1
argv.go
|
@ -12,6 +12,7 @@ type args struct {
|
|||
Package string `arg:"--package" help:"the package name"`
|
||||
Proto string `arg:"--proto" help:"the .proto filename"`
|
||||
Mutex bool `arg:"--mutex" default:"true" help:"insert a mutex into protoc .pb.go file"`
|
||||
Marshal bool `arg:"--marshal" default:"true" help:"if you need Marshal(), per-message Mutex's fail for some reason"`
|
||||
Delete bool `arg:"--delete" help:"use delete with copy experiment"`
|
||||
DryRun bool `arg:"--dry-run" help:"show what would be run"`
|
||||
GoSrc string `arg:"--go-src" help:"default is ~/go/src. could be set to your go.work path"`
|
||||
|
|
|
@ -5,15 +5,6 @@ import (
|
|||
"io"
|
||||
)
|
||||
|
||||
func (pf *File) syncLock(w io.Writer) {
|
||||
var LOCK string = pf.Bases.Lockname
|
||||
|
||||
fmt.Fprintln(w, "// bad global lock until modifying the .pb.go file is tested")
|
||||
fmt.Fprintln(w, "// sync.RWMutex or sync.Mutex?")
|
||||
fmt.Fprintln(w, "var "+LOCK+" sync.RWMutex")
|
||||
fmt.Fprintln(w, "")
|
||||
}
|
||||
|
||||
func (msg *MsgName) iterTop(w io.Writer) {
|
||||
var BASE string = msg.Name
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ func (msg *MsgName) getLockname(s string) string {
|
|||
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
|
||||
|
|
Loading…
Reference in New Issue