Skip to content

Commit

Permalink
fix(boost): use atomic AddInt32 to modify wait group counter (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
plastikfan committed Nov 2, 2023
1 parent 66df4a6 commit 18e69a1
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.52.2
version: v1.54.2
args: --verbose

test:
Expand Down
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,4 @@ linters:

run:
issues-exit-code: 1
timeout: 5m
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"Assistable",
"bodyclose",
"coverpkg",
"coverprofile",
"cubiest",
"deadcode",
"depguard",
Expand All @@ -24,27 +25,33 @@
"gocyclo",
"gofmt",
"goimports",
"golangci",
"goleak",
"gomnd",
"gosec",
"gosimple",
"goveralls",
"govet",
"graffico",
"ineffassign",
"jibberjabber",
"leaktest",
"linters",
"lorax",
"mattn",
"nakedret",
"nolint",
"nolintlint",
"onsi",
"passthru",
"pixa",
"prealloc",
"repotoken",
"shogo",
"sidewalk",
"skeletor",
"smaug",
"snivilised",
"staticcheck",
"structcheck",
"stylecheck",
Expand Down
5 changes: 3 additions & 2 deletions boost/annotated-wait-group.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"strings"
"sync"
"sync/atomic"

"github.com/samber/lo"
)
Expand Down Expand Up @@ -74,7 +75,7 @@ type waitGroupAnImpl struct {
}

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

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

func (a *waitGroupAnImpl) Done(name ...GoRoutineName) {
a.counter--
atomic.AddInt32(&a.counter, int32(-1))

if len(name) > 0 {
delete(a.names, name[0])
Expand Down

0 comments on commit 18e69a1

Please sign in to comment.