all: Use new Go 1.19 atomic types (#8772)

This commit is contained in:
greatroar
2023-02-07 12:07:34 +01:00
committed by GitHub
parent 882b711958
commit 38f2b34d29
19 changed files with 94 additions and 121 deletions
+2 -3
View File
@@ -13,7 +13,6 @@ import (
"math/rand"
"path/filepath"
"sort"
"sync/atomic"
"time"
"github.com/syncthing/syncthing/lib/config"
@@ -142,8 +141,8 @@ func newFolder(model *model, fset *db.FileSet, ignores *ignore.Matcher, cfg conf
}
func (f *folder) Serve(ctx context.Context) error {
atomic.AddInt32(&f.model.foldersRunning, 1)
defer atomic.AddInt32(&f.model.foldersRunning, -1)
f.model.foldersRunning.Add(1)
defer f.model.foldersRunning.Add(-1)
f.ctx = ctx
+2 -1
View File
@@ -23,6 +23,7 @@ import (
"runtime"
"strings"
stdsync "sync"
"sync/atomic"
"time"
"github.com/thejerf/suture/v4"
@@ -166,7 +167,7 @@ type model struct {
indexHandlers map[protocol.DeviceID]*indexHandlerRegistry
// for testing only
foldersRunning int32
foldersRunning atomic.Int32
}
var _ config.Verifier = &model{}
+2 -3
View File
@@ -21,7 +21,6 @@ import (
"strconv"
"strings"
"sync"
"sync/atomic"
"testing"
"time"
@@ -3097,7 +3096,7 @@ func TestFolderRestartZombies(t *testing.T) {
m.ScanFolder("default")
// Check how many running folders we have running before the test.
if r := atomic.LoadInt32(&m.foldersRunning); r != 1 {
if r := m.foldersRunning.Load(); r != 1 {
t.Error("Expected one running folder, not", r)
}
@@ -3122,7 +3121,7 @@ func TestFolderRestartZombies(t *testing.T) {
wg.Wait()
// Make sure the folder is up and running, because we want to count it.
m.ScanFolder("default")
if r := atomic.LoadInt32(&m.foldersRunning); r != 1 {
if r := m.foldersRunning.Load(); r != 1 {
t.Error("Expected one running folder, not", r)
}
}