...
1
2
3 package concurrent
4
5 import "sync"
6
7
8 type Map struct {
9 lock sync.RWMutex
10 data map[interface{}]interface{}
11 }
12
13
14 func NewMap() *Map {
15 return &Map{
16 data: make(map[interface{}]interface{}, 32),
17 }
18 }
19
20
21 func (m *Map) Load(key interface{}) (elem interface{}, found bool) {
22 m.lock.RLock()
23 elem, found = m.data[key]
24 m.lock.RUnlock()
25 return
26 }
27
28
29 func (m *Map) Store(key interface{}, elem interface{}) {
30 m.lock.Lock()
31 m.data[key] = elem
32 m.lock.Unlock()
33 }
34
View as plain text