mirror of
https://github.com/charlienet/go-mixed.git
synced 2025-07-18 00:22:41 +08:00
22 lines
276 B
Go
22 lines
276 B
Go
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()
|
|
}
|
|
}
|