增加map读写锁

This commit is contained in:
hahwu 2026-01-07 15:53:05 +08:00
parent 4a4fdccddf
commit 8d82a2cf15
2 changed files with 10 additions and 1 deletions

View File

@ -49,6 +49,11 @@ func Init() {
registerFunc(msg.CLUSTER_EXIT, ClusterExit)
}
// GetCallbackChanMu 返回 CallbackChan 的读写锁,供外部包安全访问 CallbackChan
func GetCallbackChanMu() *sync.RWMutex {
return &callbackChanMu
}
func Destroy() {
if server != nil {
log.Release("closing cluster server")

View File

@ -282,7 +282,11 @@ func PlayerMsgHandler(data *msg.Msg) (interface{}, error) {
func PlayerReplyMsgHandler(data *msg.Msg) (interface{}, error) {
// 先处理同步回调
if data.UniKey != "" {
if chanel, ok := mergeCluster.CallbackChan[data.UniKey]; ok {
mergeCluster.GetCallbackChanMu().RLock()
chanel, ok := mergeCluster.CallbackChan[data.UniKey]
mergeCluster.GetCallbackChanMu().RUnlock()
if ok {
log.Debug("reply message ")
chanel <- data
}