1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-07 04:23:49 +08:00

fix: data race && cgo build.

This commit is contained in:
wdvxdr 2021-07-12 11:39:46 +08:00
parent c6994ade94
commit ca93d4de0d
No known key found for this signature in database
GPG Key ID: 55FF1414A69CEBA6
3 changed files with 8 additions and 4 deletions

View File

@ -33,8 +33,8 @@ var json = jsoniter.ConfigCompatibleWithStandardLibrary
type CQBot struct {
Client *client.QQClient
lock sync.RWMutex
events []func(*Event)
mu sync.Mutex
db *leveldb.DB
friendReqCache sync.Map
@ -154,9 +154,9 @@ func NewQQBot(cli *client.QQClient, conf *config.Config) *CQBot {
// OnEventPush 注册事件上报函数
func (bot *CQBot) OnEventPush(f func(e *Event)) {
bot.mu.Lock()
defer bot.mu.Unlock()
bot.lock.Lock()
bot.events = append(bot.events, f)
bot.lock.Unlock()
}
// GetMessage 获取给定消息id对应的消息
@ -432,6 +432,9 @@ func (bot *CQBot) Release() {
}
func (bot *CQBot) dispatchEventMessage(m MSG) {
bot.lock.RLock()
defer bot.lock.RUnlock()
event := &Event{RawMsg: m}
wg := sync.WaitGroup{}
wg.Add(len(bot.events))

View File

@ -1,5 +1,6 @@
// +build linux windows,!arm darwin
// +build 386 amd64 arm arm64
// +build !cgo
// Package codec Slik编码核心模块
package codec

View File

@ -1,4 +1,4 @@
// +build !arm,!arm64,!amd64,!386
// +build !arm,!arm64,!amd64,!386 cgo
package codec