move mutex to memory

This commit is contained in:
Asim Aslam 2019-10-14 22:38:22 +01:00
parent b1fed01752
commit 247249050b

View File

@ -1,5 +1,5 @@
// Package mutex provides a sync.Mutex implementation of the lock for local use // Package memoy provides a sync.Mutex implementation of the lock for local use
package mutex package memory
import ( import (
"sync" "sync"
@ -8,7 +8,7 @@ import (
lock "github.com/micro/go-micro/sync/lock" lock "github.com/micro/go-micro/sync/lock"
) )
type mutexLock struct { type memoryLock struct {
sync.RWMutex sync.RWMutex
locks map[string]*mlock locks map[string]*mlock
} }
@ -20,7 +20,7 @@ type mlock struct {
release chan bool release chan bool
} }
func (m *mutexLock) Acquire(id string, opts ...lock.AcquireOption) error { func (m *memoryLock) Acquire(id string, opts ...lock.AcquireOption) error {
// lock our access // lock our access
m.Lock() m.Lock()
@ -107,7 +107,7 @@ lockLoop:
return nil return nil
} }
func (m *mutexLock) Release(id string) error { func (m *memoryLock) Release(id string) error {
m.Lock() m.Lock()
defer m.Unlock() defer m.Unlock()
@ -136,7 +136,7 @@ func NewLock(opts ...lock.Option) lock.Lock {
o(&options) o(&options)
} }
return &mutexLock{ return &memoryLock{
locks: make(map[string]*mlock), locks: make(map[string]*mlock),
} }
} }