Skip to content

Commit 18e69a1

Browse files
committed
fix(boost): use atomic AddInt32 to modify wait group counter (#91)
1 parent 66df4a6 commit 18e69a1

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

.github/workflows/ci-workflow.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- name: golangci-lint
1515
uses: golangci/golangci-lint-action@v3
1616
with:
17-
version: v1.52.2
17+
version: v1.54.2
1818
args: --verbose
1919

2020
test:

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,4 @@ linters:
6464

6565
run:
6666
issues-exit-code: 1
67+
timeout: 5m

.vscode/settings.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"Assistable",
88
"bodyclose",
99
"coverpkg",
10+
"coverprofile",
1011
"cubiest",
1112
"deadcode",
1213
"depguard",
@@ -24,27 +25,33 @@
2425
"gocyclo",
2526
"gofmt",
2627
"goimports",
28+
"golangci",
2729
"goleak",
2830
"gomnd",
2931
"gosec",
3032
"gosimple",
33+
"goveralls",
3134
"govet",
3235
"graffico",
3336
"ineffassign",
3437
"jibberjabber",
3538
"leaktest",
3639
"linters",
3740
"lorax",
41+
"mattn",
3842
"nakedret",
3943
"nolint",
4044
"nolintlint",
45+
"onsi",
4146
"passthru",
4247
"pixa",
4348
"prealloc",
4449
"repotoken",
50+
"shogo",
4551
"sidewalk",
4652
"skeletor",
4753
"smaug",
54+
"snivilised",
4855
"staticcheck",
4956
"structcheck",
5057
"stylecheck",

boost/annotated-wait-group.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"strings"
66
"sync"
7+
"sync/atomic"
78

89
"github.com/samber/lo"
910
)
@@ -74,7 +75,7 @@ type waitGroupAnImpl struct {
7475
}
7576

7677
func (a *waitGroupAnImpl) Add(delta int, name ...GoRoutineName) {
77-
a.counter += int32(delta)
78+
atomic.AddInt32(&a.counter, int32(delta))
7879

7980
if len(name) > 0 {
8081
a.names[name[0]] = "foo"
@@ -84,7 +85,7 @@ func (a *waitGroupAnImpl) Add(delta int, name ...GoRoutineName) {
8485
}
8586

8687
func (a *waitGroupAnImpl) Done(name ...GoRoutineName) {
87-
a.counter--
88+
atomic.AddInt32(&a.counter, int32(-1))
8889

8990
if len(name) > 0 {
9091
delete(a.names, name[0])

0 commit comments

Comments
 (0)