1
0
mirror of https://github.com/charlienet/go-mixed.git synced 2025-07-18 00:22:41 +08:00
This commit is contained in:
2022-05-10 15:08:29 +08:00
parent cd0740f443
commit aac79b4997
2 changed files with 36 additions and 0 deletions

15
locker/empty_locker.go Normal file
View File

@ -0,0 +1,15 @@
package locker
import "sync"
var _ sync.Locker = &emptyLocker{}
type emptyLocker struct{}
func NewEmptyLocker() *emptyLocker {
return &emptyLocker{}
}
func (l *emptyLocker) Lock() {}
func (l *emptyLocker) Unlock() {}

21
locker/locker.go Normal file
View 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()
}
}