mirror of
https://github.com/charlienet/go-mixed.git
synced 2025-07-18 00:22:41 +08:00
locker
This commit is contained in:
21
locker/locker.go
Normal file
21
locker/locker.go
Normal file
@ -0,0 +1,21 @@
|
||||
package locker
|
||||
|
||||
import "sync"
|
||||
|
||||
var locks = make(map[string]sync.Locker)
|
||||
|
||||
func Lock(name string) {
|
||||
if l, ok := locks[name]; ok {
|
||||
l.Lock()
|
||||
}
|
||||
|
||||
new := &sync.Mutex{}
|
||||
locks[name] = new
|
||||
new.Lock()
|
||||
}
|
||||
|
||||
func Unlock(name string) {
|
||||
if l, ok := locks[name]; ok {
|
||||
l.Unlock()
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user