MCPcopy Index your code
hub / github.com/aceld/zinx / doSetWithLockCheckWithFunc

Method doSetWithLockCheckWithFunc

zutils/shard_lock_map.go:223–235  ·  view source on GitHub ↗

doSetWithLockCheckWithFunc performs a set operation with function execution inside lock

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

Source from the content-addressed store, hash-verified

221
222// doSetWithLockCheckWithFunc performs a set operation with function execution inside lock
223func (slm ShardLockMaps) doSetWithLockCheckWithFunc(key string, f func(key string) interface{}) (interface{}, bool) {
224 shard := slm.GetShard(key)
225 shard.Lock()
226 defer shard.Unlock()
227
228 if got, ok := shard.items[key]; ok {
229 return got, false
230 }
231
232 val := f(key)
233 shard.items[key] = val
234 return val, true
235}
236
237// Clear removes all items from map.
238func (slm ShardLockMaps) Clear() {

Callers 1

GetOrSetFuncLockMethod · 0.95

Calls 1

GetShardMethod · 0.95

Tested by

no test coverage detected