1
This commit is contained in:
parent
550a64387e
commit
330f53df3d
23
sysutils.go
23
sysutils.go
@ -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":
|
||||||
|
Loading…
x
Reference in New Issue
Block a user