File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -14,39 +14,43 @@ func NewKeyRWMutex() *KeyRWMutex {
1414}
1515
1616func (kl * KeyRWMutex ) Lock (key interface {}) {
17- ok , lock := kl .lock (key )
17+ ok , lock := kl .rlock (key )
1818 if ! ok {
1919 lock = & sync.RWMutex {}
20- kl .mutexes [key ] = lock
20+ func () {
21+ kl .mu .Lock ()
22+ defer kl .mu .Unlock ()
23+ kl .mutexes [key ] = lock
24+ }()
2125 }
2226 lock .Lock ()
2327}
2428
25- func (kl * KeyRWMutex ) lock (key interface {}) (ok bool , lock * sync.RWMutex ) {
29+ func (kl * KeyRWMutex ) rlock (key interface {}) (ok bool , lock * sync.RWMutex ) {
2630 kl .mu .RLock ()
2731 defer kl .mu .RUnlock ()
2832 lock , ok = kl .mutexes [key ]
2933 return
3034}
3135
3236func (kl * KeyRWMutex ) RLock (key interface {}) {
33- ok , lock := kl .lock (key )
37+ ok , lock := kl .rlock (key )
3438
3539 if ok {
3640 lock .RLock ()
3741 }
3842}
3943
4044func (kl * KeyRWMutex ) Unlock (key interface {}) {
41- ok , lock := kl .lock (key )
45+ ok , lock := kl .rlock (key )
4246
4347 if ok {
4448 lock .Unlock ()
4549 }
4650}
4751
4852func (kl * KeyRWMutex ) RUnlock (key interface {}) {
49- ok , lock := kl .lock (key )
53+ ok , lock := kl .rlock (key )
5054
5155 if ok {
5256 lock .RUnlock ()
Original file line number Diff line number Diff line change @@ -61,11 +61,11 @@ func (sess *Session) AddMessage(message internal.A) {
6161 sess .messagesLock .RLock ()
6262 defer sess .messagesLock .RUnlock ()
6363 if sess .messagesIndex == uint8 (len (sess .messages )) {
64- time .Sleep (time .Millisecond * 100 )
6564 wait = true
6665 }
6766 }()
6867 if wait {
68+ time .Sleep (time .Millisecond * 100 )
6969 continue
7070 }
7171 func () {
You can’t perform that action at this time.
0 commit comments