This commit is contained in:
aozhiwei 2024-06-16 15:58:30 +08:00
parent 550a64387e
commit 330f53df3d

View File

@ -73,6 +73,29 @@ func ReleaseLock(l *sync.Mutex) {
l.Unlock() l.Unlock()
} }
func BatchAllocLock(keys []string) []*sync.Mutex {
locks := []*sync.Mutex{}
lock := sync.Mutex{}
for _, key := range keys {
go func () {
l := AllocLock(key)
lock.Lock()
q5.AppendSlice(&locks, l)
lock.Unlock()
}()
}
for len(locks) < len(keys) {
time.Sleep(time.Millisecond * 10)
}
return locks
}
func BatchReleaseLock(locks []*sync.Mutex) {
for _, val := range locks {
ReleaseLock(val)
}
}
func init() { func init() {
switch os.Getenv("SERVER_ENV") { switch os.Getenv("SERVER_ENV") {
case "TEST": case "TEST":