From becaf43dcb3e9832c3eb951ff9908ed697868152 Mon Sep 17 00:00:00 2001 From: aarzilli Date: Tue, 1 Mar 2016 15:41:38 +0100 Subject: Read/Write mutex for Extensions map --- nexgb/xgbgen/context.go | 5 ++--- nexgb/xgbgen/go_request_reply.go | 4 ++++ 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'nexgb/xgbgen') diff --git a/nexgb/xgbgen/context.go b/nexgb/xgbgen/context.go index f64f339..f18fd67 100644 --- a/nexgb/xgbgen/context.go +++ b/nexgb/xgbgen/context.go @@ -99,8 +99,9 @@ func (c *Context) Morph(xmlBytes []byte) { "on the server.\")", xname) c.Putln("}") c.Putln("") - c.Putln("xgb.ExtLock.Lock()") + c.Putln("c.ExtLock.Lock()") c.Putln("c.Extensions[\"%s\"] = reply.MajorOpcode", xname) + c.Putln("c.ExtLock.Unlock()") c.Putln("for evNum, fun := range xgb.NewExtEventFuncs[\"%s\"] {", xname) c.Putln("xgb.NewEventFuncs[int(reply.FirstEvent) + evNum] = fun") @@ -109,8 +110,6 @@ func (c *Context) Morph(xmlBytes []byte) { xname) c.Putln("xgb.NewErrorFuncs[int(reply.FirstError) + errNum] = fun") c.Putln("}") - c.Putln("xgb.ExtLock.Unlock()") - c.Putln("") c.Putln("return nil") c.Putln("}") c.Putln("") diff --git a/nexgb/xgbgen/go_request_reply.go b/nexgb/xgbgen/go_request_reply.go index c1b9ee9..396305e 100644 --- a/nexgb/xgbgen/go_request_reply.go +++ b/nexgb/xgbgen/go_request_reply.go @@ -79,6 +79,8 @@ func (r *Request) CheckExt(c *Context) { if !c.protocol.isExt() { return } + c.Putln("c.ExtLock.RLock()") + c.Putln("defer c.ExtLock.RUnlock()") c.Putln("if _, ok := c.Extensions[\"%s\"]; !ok {", c.protocol.ExtXName) c.Putln("panic(\"Cannot issue request '%s' using the uninitialized "+ "extension '%s'. %s.Init(connObj) must be called first.\")", @@ -169,7 +171,9 @@ func (r *Request) WriteRequest(c *Context) { c.Putln("buf := make([]byte, size)") c.Putln("") if c.protocol.isExt() { + c.Putln("c.ExtLock.RLock()") c.Putln("buf[b] = c.Extensions[\"%s\"]", c.protocol.ExtXName) + c.Putln("c.ExtLock.RUnlock()") c.Putln("b += 1") c.Putln("") } -- cgit v1.2.3