VOL-1624 Support for tech-profile creation on the first flow that references the tp-id (in write-metadata)
Getting meter from flow itself and bug fixes
Bug fix for dhcp packet-out
Change-Id: Ia466988bfdbfe49fd9a44729a4ba4a30fd991c54
diff --git a/vendor/github.com/opencord/voltha-go/db/model/child_type.go b/vendor/github.com/opencord/voltha-go/db/model/child_type.go
index da6f688..250de9c 100644
--- a/vendor/github.com/opencord/voltha-go/db/model/child_type.go
+++ b/vendor/github.com/opencord/voltha-go/db/model/child_type.go
@@ -27,18 +27,50 @@
"sync"
)
-type singletonChildTypeCache struct {
+type childTypesSingleton struct {
+ mutex sync.RWMutex
Cache map[interface{}]map[string]*ChildType
}
-var instanceChildTypeCache *singletonChildTypeCache
-var onceChildTypeCache sync.Once
+var instanceChildTypes *childTypesSingleton
+var onceChildTypes sync.Once
-func getChildTypeCache() *singletonChildTypeCache {
- onceChildTypeCache.Do(func() {
- instanceChildTypeCache = &singletonChildTypeCache{}
+func getChildTypes() *childTypesSingleton {
+ onceChildTypes.Do(func() {
+ instanceChildTypes = &childTypesSingleton{}
})
- return instanceChildTypeCache
+ return instanceChildTypes
+}
+
+func (s *childTypesSingleton) GetCache() map[interface{}]map[string]*ChildType {
+ s.mutex.RLock()
+ defer s.mutex.RUnlock()
+ return s.Cache
+}
+
+func (s *childTypesSingleton) SetCache(cache map[interface{}]map[string]*ChildType) {
+ s.mutex.Lock()
+ defer s.mutex.Unlock()
+ s.Cache = cache
+}
+
+func (s *childTypesSingleton) GetCacheEntry(key interface{}) (map[string]*ChildType, bool) {
+ s.mutex.RLock()
+ defer s.mutex.RUnlock()
+ childTypeMap, exists := s.Cache[key]
+ return childTypeMap, exists
+}
+
+func (s *childTypesSingleton) SetCacheEntry(key interface{}, value map[string]*ChildType) {
+ s.mutex.Lock()
+ defer s.mutex.Unlock()
+ s.Cache[key] = value
+}
+
+func (s *childTypesSingleton) ResetCache() {
+ s.mutex.Lock()
+ defer s.mutex.Unlock()
+ s.Cache = make(map[interface{}]map[string]*ChildType)
}
// ChildType structure contains construct details of an object
@@ -58,12 +90,12 @@
var names map[string]*ChildType
var namesExist bool
- if getChildTypeCache().Cache == nil {
- getChildTypeCache().Cache = make(map[interface{}]map[string]*ChildType)
+ if getChildTypes().Cache == nil {
+ getChildTypes().Cache = make(map[interface{}]map[string]*ChildType)
}
msgType := reflect.TypeOf(cls)
- inst := getChildTypeCache()
+ inst := getChildTypes()
if names, namesExist = inst.Cache[msgType.String()]; !namesExist {
names = make(map[string]*ChildType)
@@ -127,9 +159,10 @@
}
}
- getChildTypeCache().Cache[msgType.String()] = names
+ getChildTypes().Cache[msgType.String()] = names
} else {
- log.Debugf("Cache entry for %s: %+v", msgType.String(), inst.Cache[msgType.String()])
+ entry, _ := inst.GetCacheEntry(msgType.String())
+ log.Debugf("Cache entry for %s: %+v", msgType.String(), entry)
}
return names