You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
447 B
26 lines
447 B
2 years ago
|
package oauth
|
||
3 years ago
|
|
||
|
import "sync"
|
||
|
|
||
|
// CredentialLock 针对存储策略凭证的锁
|
||
|
type CredentialLock interface {
|
||
|
Lock(uint)
|
||
|
Unlock(uint)
|
||
|
}
|
||
|
|
||
|
var GlobalMutex = mutexMap{}
|
||
|
|
||
|
type mutexMap struct {
|
||
|
locks sync.Map
|
||
|
}
|
||
|
|
||
|
func (m *mutexMap) Lock(id uint) {
|
||
|
lock, _ := m.locks.LoadOrStore(id, &sync.Mutex{})
|
||
|
lock.(*sync.Mutex).Lock()
|
||
|
}
|
||
|
|
||
|
func (m *mutexMap) Unlock(id uint) {
|
||
|
lock, _ := m.locks.LoadOrStore(id, &sync.Mutex{})
|
||
|
lock.(*sync.Mutex).Unlock()
|
||
|
}
|