import (
"path"
"path/filepath"
+ "sync"
)
-var TgtCache = make(map[string]*Tgt)
+var (
+ TgtCache = make(map[string]*Tgt)
+ TgtCacheM sync.RWMutex
+)
func mustAbs(pth string) string {
pth, err := filepath.Abs(pth)
func NewTgt(tgt string) *Tgt {
a := mustAbs(tgt)
- if TgtCache != nil {
- if t := TgtCache[a]; t != nil {
- return t
- }
+ TgtCacheM.RLock()
+ cached := TgtCache[a]
+ TgtCacheM.RUnlock()
+ if cached != nil {
+ return cached
}
h, t := pathSplit(a)
res := Tgt{
rel: mustRel(Cwd, a),
dep: path.Join(h, RedoDir, t+DepSuffix),
}
- if TgtCache != nil {
- TgtCache[a] = &res
- }
+ TgtCacheM.Lock()
+ TgtCache[a] = &res
+ TgtCacheM.Unlock()
return &res
}