summaryrefslogtreecommitdiff
path: root/vendor/git.iim.gay/grufwub/go-mutexes
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/git.iim.gay/grufwub/go-mutexes')
-rw-r--r--vendor/git.iim.gay/grufwub/go-mutexes/map.go24
-rw-r--r--vendor/git.iim.gay/grufwub/go-mutexes/mutex_timeout.go11
2 files changed, 14 insertions, 21 deletions
diff --git a/vendor/git.iim.gay/grufwub/go-mutexes/map.go b/vendor/git.iim.gay/grufwub/go-mutexes/map.go
index 1e5b2781a..ea917ee5e 100644
--- a/vendor/git.iim.gay/grufwub/go-mutexes/map.go
+++ b/vendor/git.iim.gay/grufwub/go-mutexes/map.go
@@ -8,15 +8,7 @@ import (
// by key. You do not need to worry about managing the contents of the map,
// only requesting RLock/Lock for keys, and ensuring to call the returned
// unlock functions.
-type MutexMap interface {
- // Lock acquires a mutex lock for supplied key, returning an Unlock function
- Lock(key string) (unlock func())
-
- // RLock acquires a mutex read lock for supplied key, returning an RUnlock function
- RLock(key string) (runlock func())
-}
-
-type mutexMap struct {
+type MutexMap struct {
// NOTE:
// Individual keyed mutexes should ONLY ever
// be locked within the protection of the outer
@@ -35,7 +27,7 @@ func NewMap(newFn func() RWMutex) MutexMap {
if newFn == nil {
newFn = NewRW
}
- return &mutexMap{
+ return MutexMap{
mus: make(map[string]RWMutex),
mapMu: sync.Mutex{},
pool: sync.Pool{
@@ -46,7 +38,7 @@ func NewMap(newFn func() RWMutex) MutexMap {
}
}
-func (mm *mutexMap) evict(key string, mu RWMutex) {
+func (mm *MutexMap) evict(key string, mu RWMutex) {
// Acquire map lock
mm.mapMu.Lock()
@@ -63,21 +55,21 @@ func (mm *mutexMap) evict(key string, mu RWMutex) {
mm.pool.Put(mu)
}
-// GetRLock acquires a mutex read lock for supplied key, returning an RUnlock function
-func (mm *mutexMap) RLock(key string) func() {
+// RLock acquires a mutex read lock for supplied key, returning an RUnlock function
+func (mm *MutexMap) RLock(key string) func() {
return mm.getLock(key, func(mu RWMutex) func() {
return mu.RLock()
})
}
-// GetLock acquires a mutex lock for supplied key, returning an Unlock function
-func (mm *mutexMap) Lock(key string) func() {
+// Lock acquires a mutex lock for supplied key, returning an Unlock function
+func (mm *MutexMap) Lock(key string) func() {
return mm.getLock(key, func(mu RWMutex) func() {
return mu.Lock()
})
}
-func (mm *mutexMap) getLock(key string, doLock func(RWMutex) func()) func() {
+func (mm *MutexMap) getLock(key string, doLock func(RWMutex) func()) func() {
// Get map lock
mm.mapMu.Lock()
diff --git a/vendor/git.iim.gay/grufwub/go-mutexes/mutex_timeout.go b/vendor/git.iim.gay/grufwub/go-mutexes/mutex_timeout.go
index ffda6e890..65ca9f39e 100644
--- a/vendor/git.iim.gay/grufwub/go-mutexes/mutex_timeout.go
+++ b/vendor/git.iim.gay/grufwub/go-mutexes/mutex_timeout.go
@@ -43,7 +43,7 @@ type timeoutMutex struct {
}
func (mu *timeoutMutex) Lock() func() {
- return mu.LockFunc(func() { panic("timed out") })
+ return mu.LockFunc(func() { panic("lock timed out") })
}
func (mu *timeoutMutex) LockFunc(fn func()) func() {
@@ -58,7 +58,7 @@ type timeoutRWMutex struct {
}
func (mu *timeoutRWMutex) Lock() func() {
- return mu.LockFunc(func() { panic("timed out") })
+ return mu.LockFunc(func() { panic("lock timed out") })
}
func (mu *timeoutRWMutex) LockFunc(fn func()) func() {
@@ -66,7 +66,7 @@ func (mu *timeoutRWMutex) LockFunc(fn func()) func() {
}
func (mu *timeoutRWMutex) RLock() func() {
- return mu.RLockFunc(func() { panic("timed out") })
+ return mu.RLockFunc(func() { panic("rlock timed out") })
}
func (mu *timeoutRWMutex) RLockFunc(fn func()) func() {
@@ -76,7 +76,8 @@ func (mu *timeoutRWMutex) RLockFunc(fn func()) func() {
// timeoutPool provides nowish.Timeout objects for timeout mutexes
var timeoutPool = sync.Pool{
New: func() interface{} {
- return nowish.NewTimeout()
+ t := nowish.NewTimeout()
+ return &t
},
}
@@ -88,7 +89,7 @@ func mutexTimeout(d time.Duration, unlock func(), fn func()) func() {
}
// Acquire timeout obj
- t := timeoutPool.Get().(nowish.Timeout)
+ t := timeoutPool.Get().(*nowish.Timeout)
// Start the timeout with hook
t.Start(d, fn)