diff options
author | jw_wonny.cha <jw_wonny.cha@samsung.com> | 2019-04-02 19:07:08 +0900 |
---|---|---|
committer | jw_wonny.cha <jw_wonny.cha@samsung.com> | 2019-04-02 19:07:08 +0900 |
commit | 5b8ebcd180555b4266527de888605cf5bad0117b (patch) | |
tree | b9a4f053ccda521c98110c1738ec89d99a0b9077 | |
parent | b02732e697192d8354c3a77d4906c72c3e198250 (diff) | |
download | edge-orchestration-servicemgr.tar.gz edge-orchestration-servicemgr.tar.bz2 edge-orchestration-servicemgr.zip |
- merged typeservicemgr
-rw-r--r-- | src/servicemgr/types.go | 56 | ||||
-rw-r--r-- | src/servicemgr/types_concurrent_map.go | 59 |
2 files changed, 56 insertions, 59 deletions
diff --git a/src/servicemgr/types.go b/src/servicemgr/types.go index e0867ee..2e7edde 100644 --- a/src/servicemgr/types.go +++ b/src/servicemgr/types.go @@ -1,5 +1,7 @@ package servicemgr +import "sync" + var logPrefix = "servicemgr" // ServiceParam structrue @@ -42,3 +44,57 @@ type StatusNotification struct { ServiceID uint64 `json:"ServiceID"` Status string `json:"Status"` } + +type ConcurrentMap struct { + sync.RWMutex + items map[uint64]interface{} +} + +// ConcurrentMapItem type +type ConcurrentMapItem struct { + Key uint64 + Value interface{} +} + +// Set is for setting map item +func (cm *ConcurrentMap) Set(key uint64, value interface{}) { + cm.Lock() + defer cm.Unlock() + + cm.items[key] = value +} + +// Get is for getting map item +func (cm *ConcurrentMap) Get(key uint64) (interface{}, bool) { + cm.Lock() + defer cm.Unlock() + + value, ok := cm.items[key] + + return value, ok +} + +// Remove is for removing map item +func (cm *ConcurrentMap) Remove(key uint64) { + cm.Lock() + defer cm.Unlock() + + delete(cm.items, key) +} + +// Iter is for iterating map item +func (cm *ConcurrentMap) Iter() <-chan ConcurrentMapItem { + c := make(chan ConcurrentMapItem) + + go func() { + cm.Lock() + defer cm.Unlock() + + for k, v := range cm.items { + c <- ConcurrentMapItem{k, v} + } + close(c) + }() + + return c +} diff --git a/src/servicemgr/types_concurrent_map.go b/src/servicemgr/types_concurrent_map.go deleted file mode 100644 index 4bc2a19..0000000 --- a/src/servicemgr/types_concurrent_map.go +++ /dev/null @@ -1,59 +0,0 @@ -package servicemgr - -import "sync" - -// ConcurrentMap type -type ConcurrentMap struct { - sync.RWMutex - items map[uint64]interface{} -} - -// ConcurrentMapItem type -type ConcurrentMapItem struct { - Key uint64 - Value interface{} -} - -// Set is for setting map item -func (cm *ConcurrentMap) Set(key uint64, value interface{}) { - cm.Lock() - defer cm.Unlock() - - cm.items[key] = value -} - -// Get is for getting map item -func (cm *ConcurrentMap) Get(key uint64) (interface{}, bool) { - cm.Lock() - defer cm.Unlock() - - value, ok := cm.items[key] - - return value, ok -} - -// Remove is for removing map item -func (cm *ConcurrentMap) Remove(key uint64) { - cm.Lock() - defer cm.Unlock() - - delete(cm.items, key) -} - -// Iter is for iterating map item -func (cm *ConcurrentMap) Iter() <-chan ConcurrentMapItem { - c := make(chan ConcurrentMapItem) - - f := func() { - cm.Lock() - defer cm.Unlock() - - for k, v := range cm.items { - c <- ConcurrentMapItem{k, v} - } - close(c) - } - go f() - - return c -} |