mirror of https://github.com/go-gitea/gitea
Git with a cup of tea, painless self-hosted git service
Mirror for internal git.with.parts use
https://git.with.parts
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
642 B
33 lines
642 B
//+build !go1.9
|
|
|
|
package concurrent
|
|
|
|
import "sync"
|
|
|
|
// Map implements a thread safe map for go version below 1.9 using mutex
|
|
type Map struct {
|
|
lock sync.RWMutex
|
|
data map[interface{}]interface{}
|
|
}
|
|
|
|
// NewMap creates a thread safe map
|
|
func NewMap() *Map {
|
|
return &Map{
|
|
data: make(map[interface{}]interface{}, 32),
|
|
}
|
|
}
|
|
|
|
// Load is same as sync.Map Load
|
|
func (m *Map) Load(key interface{}) (elem interface{}, found bool) {
|
|
m.lock.RLock()
|
|
elem, found = m.data[key]
|
|
m.lock.RUnlock()
|
|
return
|
|
}
|
|
|
|
// Load is same as sync.Map Store
|
|
func (m *Map) Store(key interface{}, elem interface{}) {
|
|
m.lock.Lock()
|
|
m.data[key] = elem
|
|
m.lock.Unlock()
|
|
}
|
|
|