package servicemgr
+import "sync"
+
var logPrefix = "servicemgr"
// ServiceParam structrue
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
+}
+++ /dev/null
-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
-}