Skip to content

Commit

Permalink
make counter atomic to stop race conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
WhoSoup committed Oct 16, 2019
1 parent e7717c4 commit df4cdf2
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions jsonrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"io/ioutil"
"net/http"
"strings"
"sync/atomic"
"time"
)

Expand Down Expand Up @@ -353,11 +354,10 @@ func walletRequest(req *JSON2Request) (*JSON2Response, error) {
}

// newCounter is used to generate the ID field for the JSON2Request
func newCounter() func() int {
count := 0
return func() int {
count += 1
return count
func newCounter() func() uint32 {
var count uint32
return func() uint32 {
return atomic.AddUint32(&count, 1)
}
}

Expand Down

0 comments on commit df4cdf2

Please sign in to comment.