diff options
author | aarzilli <alessandro.arzilli@gmail.com> | 2016-03-01 15:41:38 +0100 |
---|---|---|
committer | Přemysl Janouch <p@janouch.name> | 2018-09-08 16:49:24 +0200 |
commit | becaf43dcb3e9832c3eb951ff9908ed697868152 (patch) | |
tree | f2a45ac253c5ec8265efa78f1d4a2c993153fe18 /nexgb/bigreq | |
parent | baff8c19067489ea26bbb804ef693e966202b511 (diff) | |
download | haven-becaf43dcb3e9832c3eb951ff9908ed697868152.tar.gz haven-becaf43dcb3e9832c3eb951ff9908ed697868152.tar.xz haven-becaf43dcb3e9832c3eb951ff9908ed697868152.zip |
Read/Write mutex for Extensions map
Diffstat (limited to 'nexgb/bigreq')
-rw-r--r-- | nexgb/bigreq/bigreq.go | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/nexgb/bigreq/bigreq.go b/nexgb/bigreq/bigreq.go index d2adcc7..6590376 100644 --- a/nexgb/bigreq/bigreq.go +++ b/nexgb/bigreq/bigreq.go @@ -19,16 +19,15 @@ func Init(c *xgb.Conn) error { return xgb.Errorf("No extension named BIG-REQUESTS could be found on on the server.") } - xgb.ExtLock.Lock() + c.ExtLock.Lock() c.Extensions["BIG-REQUESTS"] = reply.MajorOpcode + c.ExtLock.Unlock() for evNum, fun := range xgb.NewExtEventFuncs["BIG-REQUESTS"] { xgb.NewEventFuncs[int(reply.FirstEvent)+evNum] = fun } for errNum, fun := range xgb.NewExtErrorFuncs["BIG-REQUESTS"] { xgb.NewErrorFuncs[int(reply.FirstError)+errNum] = fun } - xgb.ExtLock.Unlock() - return nil } @@ -69,6 +68,8 @@ type EnableCookie struct { // Enable sends a checked request. // If an error occurs, it will be returned with the reply by calling EnableCookie.Reply() func Enable(c *xgb.Conn) EnableCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() if _, ok := c.Extensions["BIG-REQUESTS"]; !ok { panic("Cannot issue request 'Enable' using the uninitialized extension 'BIG-REQUESTS'. bigreq.Init(connObj) must be called first.") } @@ -80,6 +81,8 @@ func Enable(c *xgb.Conn) EnableCookie { // EnableUnchecked sends an unchecked request. // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. func EnableUnchecked(c *xgb.Conn) EnableCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() if _, ok := c.Extensions["BIG-REQUESTS"]; !ok { panic("Cannot issue request 'Enable' using the uninitialized extension 'BIG-REQUESTS'. bigreq.Init(connObj) must be called first.") } @@ -134,7 +137,9 @@ func enableRequest(c *xgb.Conn) []byte { b := 0 buf := make([]byte, size) + c.ExtLock.RLock() buf[b] = c.Extensions["BIG-REQUESTS"] + c.ExtLock.RUnlock() b += 1 buf[b] = 0 // request opcode |