blob: b9c8df7f4101b6270690d9f6526c6e2466109d78 [file] [log] [blame]
khenaidooab1f7bd2019-11-14 14:00:27 -05001//+build !go1.9
2
3package concurrent
4
5import "sync"
6
7// Map implements a thread safe map for go version below 1.9 using mutex
8type Map struct {
9 lock sync.RWMutex
10 data map[interface{}]interface{}
11}
12
13// NewMap creates a thread safe map
14func NewMap() *Map {
15 return &Map{
16 data: make(map[interface{}]interface{}, 32),
17 }
18}
19
20// Load is same as sync.Map Load
21func (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// Load is same as sync.Map Store
29func (m *Map) Store(key interface{}, elem interface{}) {
30 m.lock.Lock()
31 m.data[key] = elem
32 m.lock.Unlock()
33}