Skip to content

Commit

Permalink
ffldb_test: Use atomic types.
Browse files Browse the repository at this point in the history
  • Loading branch information
jholdstock committed Feb 17, 2023
1 parent d722b86 commit 8f5a18b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions database/ffldb/interface_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) 2015-2016 The btcsuite developers
// Copyright (c) 2016-2020 The Decred developers
// Copyright (c) 2016-2023 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.

Expand Down Expand Up @@ -2157,17 +2157,17 @@ func testConcurrentClose(tc *testContext) bool {
// Start up a few readers and wait for them to acquire views. Each
// reader waits for a signal to complete to ensure the transactions stay
// open until they are explicitly signalled to be closed.
var activeReaders int32
var activeReaders atomic.Int32
numReaders := 3
started := make(chan struct{})
finishReaders := make(chan struct{})
resultChan := make(chan bool, numReaders+1)
reader := func() {
err := tc.db.View(func(tx database.Tx) error {
atomic.AddInt32(&activeReaders, 1)
activeReaders.Add(1)
started <- struct{}{}
<-finishReaders
atomic.AddInt32(&activeReaders, -1)
activeReaders.Add(-1)
return nil
})
if err != nil {
Expand Down Expand Up @@ -2206,7 +2206,7 @@ func testConcurrentClose(tc *testContext) bool {
// active readers open.
time.AfterFunc(time.Millisecond*250, func() { close(finishReaders) })
<-dbClosed
if nr := atomic.LoadInt32(&activeReaders); nr != 0 {
if nr := activeReaders.Load(); nr != 0 {
tc.t.Errorf("Close did not appear to block with active "+
"readers: %d active", nr)
return false
Expand Down
2 changes: 1 addition & 1 deletion database/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/decred/dcrd/database/v3

go 1.17
go 1.19

require (
github.com/decred/dcrd/chaincfg/chainhash v1.0.3
Expand Down

0 comments on commit 8f5a18b

Please sign in to comment.