Skip to content

Commit

Permalink
use atomic.(Load|Store)Int64 for requestTimeout
Browse files Browse the repository at this point in the history
  • Loading branch information
vetinari committed May 8, 2017
1 parent cb5ebe2 commit 45c93f5
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,7 @@ func (l *Conn) Close() {
// SetTimeout sets the time after a request is sent that a MessageTimeout triggers
func (l *Conn) SetTimeout(timeout time.Duration) {
if timeout > 0 {
l.timeoutMutex.Lock()
l.requestTimeout = timeout
l.timeoutMutex.Unlock()
atomic.StoreInt64((*int64)(&l.requestTimeout), int64(timeout))
}
}

Expand Down Expand Up @@ -391,9 +389,7 @@ func (l *Conn) processMessages() {
l.messageContexts[message.MessageID] = message.Context

// Add timeout if defined
l.timeoutMutex.Lock()
to := l.requestTimeout
l.timeoutMutex.Unlock()
to := time.Duration(atomic.LoadInt64((*int64)(&l.requestTimeout)))
if to > 0 {
go func() {
defer func() {
Expand Down

0 comments on commit 45c93f5

Please sign in to comment.