diff options
| author | Chris Lu <chris.lu@gmail.com> | 2016-06-02 18:09:14 -0700 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2016-06-02 18:09:14 -0700 |
| commit | 5ce6bbf07672bf3f3c8d26cd2ce0e3e853a47c44 (patch) | |
| tree | 2e4dd2ad0a618ab2b7cdebcdb9c503526c31e2e8 /go/util/concurrent_read_map.go | |
| parent | caeffa3998adc060fa66c4cd77af971ff2d26c57 (diff) | |
| download | seaweedfs-5ce6bbf07672bf3f3c8d26cd2ce0e3e853a47c44.tar.xz seaweedfs-5ce6bbf07672bf3f3c8d26cd2ce0e3e853a47c44.zip | |
directory structure change to work with glide
glide has its own requirements. My previous workaround caused me some
code checkin errors. Need to fix this.
Diffstat (limited to 'go/util/concurrent_read_map.go')
| -rw-r--r-- | go/util/concurrent_read_map.go | 60 |
1 files changed, 0 insertions, 60 deletions
diff --git a/go/util/concurrent_read_map.go b/go/util/concurrent_read_map.go deleted file mode 100644 index 28b6ae0f1..000000000 --- a/go/util/concurrent_read_map.go +++ /dev/null @@ -1,60 +0,0 @@ -package util - -import ( - "sync" -) - -// A mostly for read map, which can thread-safely -// initialize the map entries. -type ConcurrentReadMap struct { - sync.RWMutex - - items map[string]interface{} -} - -func NewConcurrentReadMap() *ConcurrentReadMap { - return &ConcurrentReadMap{items: make(map[string]interface{})} -} - -func (m *ConcurrentReadMap) initMapEntry(key string, newEntry func() interface{}) (value interface{}) { - m.Lock() - defer m.Unlock() - if value, ok := m.items[key]; ok { - return value - } - value = newEntry() - m.items[key] = value - return value -} - -func (m *ConcurrentReadMap) Get(key string, newEntry func() interface{}) interface{} { - m.RLock() - if value, ok := m.items[key]; ok { - m.RUnlock() - return value - } - m.RUnlock() - return m.initMapEntry(key, newEntry) -} - -func (m *ConcurrentReadMap) Find(key string) (interface{}, bool) { - m.RLock() - value, ok := m.items[key] - m.RUnlock() - return value, ok -} - -func (m *ConcurrentReadMap) Items() (itemsCopy []interface{}) { - m.RLock() - for _, i := range m.items { - itemsCopy = append(itemsCopy, i) - } - m.RUnlock() - return itemsCopy -} - -func (m *ConcurrentReadMap) Delete(key string) { - m.Lock() - delete(m.items, key) - m.Unlock() -} |
