fix: update lego.
This commit is contained in:
parent
b8b0c8f3e5
commit
8d848c3d60
169 changed files with 12224 additions and 605 deletions
43
vendor/github.com/sacloud/libsacloud/utils/mutexkv/mutexkv.go
generated
vendored
Normal file
43
vendor/github.com/sacloud/libsacloud/utils/mutexkv/mutexkv.go
generated
vendored
Normal file
|
@ -0,0 +1,43 @@
|
|||
package mutexkv
|
||||
|
||||
import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
// MutexKV is a simple key/value store for arbitrary mutexes. It can be used to
|
||||
// serialize changes across arbitrary collaborators that share knowledge of the
|
||||
// keys they must serialize on.
|
||||
type MutexKV struct {
|
||||
lock sync.Mutex
|
||||
store map[string]*sync.Mutex
|
||||
}
|
||||
|
||||
// Lock the mutex for the given key. Caller is responsible for calling Unlock
|
||||
// for the same key
|
||||
func (m *MutexKV) Lock(key string) {
|
||||
m.get(key).Lock()
|
||||
}
|
||||
|
||||
// Unlock the mutex for the given key. Caller must have called Lock for the same key first
|
||||
func (m *MutexKV) Unlock(key string) {
|
||||
m.get(key).Unlock()
|
||||
}
|
||||
|
||||
// Returns a mutex for the given key, no guarantee of its lock status
|
||||
func (m *MutexKV) get(key string) *sync.Mutex {
|
||||
m.lock.Lock()
|
||||
defer m.lock.Unlock()
|
||||
mutex, ok := m.store[key]
|
||||
if !ok {
|
||||
mutex = &sync.Mutex{}
|
||||
m.store[key] = mutex
|
||||
}
|
||||
return mutex
|
||||
}
|
||||
|
||||
// NewMutexKV Returns a properly initalized MutexKV
|
||||
func NewMutexKV() *MutexKV {
|
||||
return &MutexKV{
|
||||
store: make(map[string]*sync.Mutex),
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue