mirror of
https://github.com/HDT3213/godis.git
synced 2025-10-05 08:46:56 +08:00
optimize locks for sinterstore/sunionstore/sdiffstore
This commit is contained in:
@@ -126,3 +126,41 @@ func (locks *Locks) RUnLocks(keys ...string) {
|
||||
mu.RUnlock()
|
||||
}
|
||||
}
|
||||
|
||||
func (locks *Locks) RWLocks(writeKeys []string, readKeys []string) {
|
||||
keys := append(writeKeys, readKeys...)
|
||||
indices := locks.toLockIndices(keys, false)
|
||||
writeIndices := locks.toLockIndices(writeKeys, false)
|
||||
writeIndexSet := make(map[uint32]struct{})
|
||||
for _, idx := range writeIndices {
|
||||
writeIndexSet[idx] = struct{}{}
|
||||
}
|
||||
for _, index := range indices {
|
||||
_, w := writeIndexSet[index]
|
||||
mu := locks.table[index]
|
||||
if w {
|
||||
mu.Lock()
|
||||
} else {
|
||||
mu.RLock()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (locks *Locks) RWUnLocks(writeKeys []string, readKeys []string) {
|
||||
keys := append(writeKeys, readKeys...)
|
||||
indices := locks.toLockIndices(keys, true)
|
||||
writeIndices := locks.toLockIndices(writeKeys, true)
|
||||
writeIndexSet := make(map[uint32]struct{})
|
||||
for _, idx := range writeIndices {
|
||||
writeIndexSet[idx] = struct{}{}
|
||||
}
|
||||
for _, index := range indices {
|
||||
_, w := writeIndexSet[index]
|
||||
mu := locks.table[index]
|
||||
if w {
|
||||
mu.Unlock()
|
||||
} else {
|
||||
mu.RUnlock()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user