Replace Mutex with RWMutex
This commit is contained in:
parent
9f25490f61
commit
c406b182bb
2 changed files with 6 additions and 6 deletions
|
|
@ -8,13 +8,13 @@ import "sync"
|
|||
type GopenPGP struct {
|
||||
latestServerTime int64
|
||||
generationOffset int64
|
||||
lock *sync.Mutex
|
||||
lock *sync.RWMutex
|
||||
}
|
||||
|
||||
var pgp = GopenPGP{
|
||||
latestServerTime: 0,
|
||||
generationOffset: 0,
|
||||
lock: &sync.Mutex{},
|
||||
lock: &sync.RWMutex{},
|
||||
}
|
||||
|
||||
// clone returns a clone of the byte slice. Internal function used to make sure
|
||||
|
|
|
|||
|
|
@ -36,8 +36,8 @@ func GetTime() time.Time {
|
|||
|
||||
// getNow returns the latest server time.
|
||||
func getNow() time.Time {
|
||||
pgp.lock.Lock()
|
||||
defer pgp.lock.Unlock()
|
||||
pgp.lock.RLock()
|
||||
defer pgp.lock.RUnlock()
|
||||
|
||||
if pgp.latestServerTime == 0 {
|
||||
return time.Now()
|
||||
|
|
@ -53,8 +53,8 @@ func getTimeGenerator() func() time.Time {
|
|||
|
||||
// getNowKeyGenerationOffset returns the current time with the key generation offset.
|
||||
func getNowKeyGenerationOffset() time.Time {
|
||||
pgp.lock.Lock()
|
||||
defer pgp.lock.Unlock()
|
||||
pgp.lock.RLock()
|
||||
defer pgp.lock.RUnlock()
|
||||
|
||||
if pgp.latestServerTime == 0 {
|
||||
return time.Unix(time.Now().Unix()+pgp.generationOffset, 0)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue