MCPcopy Create free account
hub / github.com/aceld/zinx / GetOrSetFuncLock

Method GetOrSetFuncLock

zutils/shard_lock_map.go:201–206  ·  view source on GitHub ↗

GetOrSetFuncLock gets the value for the given key, or sets it using the provided function if it doesn't exist. The function f is called inside the lock for atomic operations. WARNING: Do not perform operations on the container within f to avoid deadlocks. Returns the value and whether it was set (tr

(key string, f func(key string) interface{})

Source from the content-addressed store, hash-verified

199// WARNING: Do not perform operations on the container within f to avoid deadlocks.
200// Returns the value and whether it was set (true) or already existed (false).
201func (slm ShardLockMaps) GetOrSetFuncLock(key string, f func(key string) interface{}) (interface{}, bool) {
202 if v, ok := slm.Get(key); ok {
203 return v, false
204 }
205 return slm.doSetWithLockCheckWithFunc(key, f)
206}
207
208// doSetWithLockCheck performs a set operation with lock checking
209func (slm ShardLockMaps) doSetWithLockCheck(key string, val interface{}) (interface{}, bool) {

Callers 1

TestGetOrSetFuncLockFunction · 0.95

Calls 2

GetMethod · 0.95

Tested by 1

TestGetOrSetFuncLockFunction · 0.76