Add lock, Fixed fatal error: concurrent map writes

This commit is contained in:
vcaesar 2019-03-15 13:45:47 -04:00
parent bbbbefb5ff
commit bc414970f3
2 changed files with 8 additions and 0 deletions

View File

@ -24,7 +24,9 @@ func go_send(s *C.char) {
} }
if out.Keychar != CharUndefined { if out.Keychar != CharUndefined {
lck.Lock()
raw2key[out.Rawcode] = string([]rune{out.Keychar}) raw2key[out.Rawcode] = string([]rune{out.Keychar})
lck.Unlock()
} }
// todo bury this deep into the C lib so that the time is correct // todo bury this deep into the C lib so that the time is correct

View File

@ -26,6 +26,7 @@ import "C"
import ( import (
"fmt" "fmt"
"sync"
"time" "time"
"unsafe" "unsafe"
) )
@ -83,6 +84,8 @@ type Event struct {
var ( var (
ev = make(chan Event, 1024) ev = make(chan Event, 1024)
asyncon = false asyncon = false
lck sync.RWMutex
) )
// String return hook kind string // String return hook kind string
@ -136,6 +139,9 @@ func (e Event) String() string {
// RawcodetoKeychar rawcode to keychar // RawcodetoKeychar rawcode to keychar
func RawcodetoKeychar(r uint16) string { func RawcodetoKeychar(r uint16) string {
lck.RLock()
defer lck.RUnlock()
return raw2key[r] return raw2key[r]
} }