mirror of
https://github.com/go-gitea/gitea.git
synced 2025-12-16 22:15:43 +08:00
Use RWMutex
This commit is contained in:
parent
e2870aaa88
commit
fb475470f0
@ -50,12 +50,21 @@ func (gpgSettings *GPGSettings) LoadPublicKeyContent() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
loadPublicGPGKeyMutex sync.Mutex
|
loadPublicGPGKeyMutex sync.RWMutex
|
||||||
globalGPGSettings *GPGSettings
|
globalGPGSettings *GPGSettings
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetDefaultPublicGPGKey will return and cache the default public GPG settings
|
// GetDefaultPublicGPGKey will return and cache the default public GPG settings
|
||||||
func GetDefaultPublicGPGKey(ctx context.Context, forceUpdate bool) (*GPGSettings, error) {
|
func GetDefaultPublicGPGKey(ctx context.Context, forceUpdate bool) (*GPGSettings, error) {
|
||||||
|
if !forceUpdate {
|
||||||
|
loadPublicGPGKeyMutex.RLock()
|
||||||
|
if globalGPGSettings != nil {
|
||||||
|
defer loadPublicGPGKeyMutex.RUnlock()
|
||||||
|
return globalGPGSettings, nil
|
||||||
|
}
|
||||||
|
loadPublicGPGKeyMutex.RUnlock()
|
||||||
|
}
|
||||||
|
|
||||||
loadPublicGPGKeyMutex.Lock()
|
loadPublicGPGKeyMutex.Lock()
|
||||||
defer loadPublicGPGKeyMutex.Unlock()
|
defer loadPublicGPGKeyMutex.Unlock()
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user