diff --git a/locker/empty_locker.go b/locker/empty_locker.go new file mode 100644 index 0000000..b29d55e --- /dev/null +++ b/locker/empty_locker.go @@ -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() {} diff --git a/locker/locker.go b/locker/locker.go new file mode 100644 index 0000000..82d214a --- /dev/null +++ b/locker/locker.go @@ -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() + } +}