Skip to content

Commit

Permalink
Use time.Now().UTC() in lieu of just time.Now()
Browse files Browse the repository at this point in the history
  • Loading branch information
fwessels committed May 22, 2017
1 parent a41e002 commit a891d7e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lmutex.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (lm *LMutex) GetLock(timeout time.Duration) (locked bool) {
// The call will block until the lock is granted using a built-in
// timing randomized back-off algorithm to try again until successful
func (lm *LMutex) lockLoop(timeout time.Duration) bool {
doneCh, start := make(chan struct{}), time.Now()
doneCh, start := make(chan struct{}), time.Now().UTC()
defer close(doneCh)

// We timed out on the previous lock, incrementally wait
Expand All @@ -59,7 +59,7 @@ func (lm *LMutex) lockLoop(timeout time.Duration) bool {
// Try to acquire the lock.
if atomic.CompareAndSwapInt64(&lm.state, NOLOCKS, WRITELOCK) {
return true
} else if time.Since(start) >= timeout { // Are we past the timeout?
} else if time.Now().UTC().Sub(start) >= timeout { // Are we past the timeout?
break
}
// We timed out on the previous lock, incrementally wait
Expand Down
4 changes: 2 additions & 2 deletions lrwmutex.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (lm *LRWMutex) GetRLock(timeout time.Duration) (locked bool) {
// The call will block until the lock is granted using a built-in
// timing randomized back-off algorithm to try again until successful
func (lm *LRWMutex) lockLoop(timeout time.Duration, isWriteLock bool) bool {
doneCh, start := make(chan struct{}), time.Now()
doneCh, start := make(chan struct{}), time.Now().UTC()
defer close(doneCh)

// We timed out on the previous lock, incrementally wait
Expand Down Expand Up @@ -104,7 +104,7 @@ func (lm *LRWMutex) lockLoop(timeout time.Duration, isWriteLock bool) bool {
if success {
return true
}
if time.Since(start) >= timeout { // Are we past the timeout?
if time.Now().UTC().Sub(start) >= timeout { // Are we past the timeout?
break
}
// We timed out on the previous lock, incrementally wait
Expand Down

0 comments on commit a891d7e

Please sign in to comment.