Skip to content

Commit

Permalink
修复并发安全
Browse files Browse the repository at this point in the history
  • Loading branch information
steden committed Jul 27, 2023
1 parent 232662f commit 7cfada3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions modules/getDependModule.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ func GetDependModule(module ...FarseerModule) []FarseerModule {
moduleName := reflect.TypeOf(farseerModule).String()
flog.LogBuffer <- fmt.Sprint("Loading Module:" + flog.Colors[5](moduleName) + "")
modules = append(modules, farseerModule)
moduleMapLocker.Lock()
moduleMap[moduleName] = 0
moduleMapLocker.Unlock()
}
return modules
}
Expand Down
5 changes: 5 additions & 0 deletions modules/moduleMap.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ import (
"fmt"
"github.com/farseer-go/fs/flog"
"reflect"
"sync"
)

var moduleMap = make(map[string]int64)
var moduleMapLocker sync.RWMutex

// IsLoad 模块是否加载
func IsLoad(module FarseerModule) bool {
moduleMapLocker.RLock()
defer moduleMapLocker.RUnlock()

moduleName := reflect.TypeOf(module).String()
_, isExists := moduleMap[moduleName]
return isExists
Expand Down

0 comments on commit 7cfada3

Please sign in to comment.