Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace custom go-concert atomic types with stdlib atomic #39980

Merged
merged 4 commits into from
Jun 24, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions libbeat/statestore/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
package statestore

import (
"sync/atomic"

"github.com/elastic/beats/v7/libbeat/statestore/backend"
"github.com/elastic/go-concert/atomic"
"github.com/elastic/go-concert/unison"
)

type sharedStore struct {
reg *Registry
refCount atomic.Int
refCount atomic.Int64

name string
backend backend.Store
Expand All @@ -43,12 +44,14 @@ type Store struct {
}

func newSharedStore(reg *Registry, name string, backend backend.Store) *sharedStore {
return &sharedStore{
s := &sharedStore{
reg: reg,
refCount: atomic.MakeInt(1),
refCount: atomic.Int64{},
name: name,
backend: backend,
}
s.refCount.Store(1)
return s
}

func newStore(shared *sharedStore) *Store {
Expand Down Expand Up @@ -151,11 +154,11 @@ func (s *Store) Each(fn func(string, ValueDecoder) (bool, error)) error {
}

func (s *sharedStore) Retain() {
s.refCount.Inc()
s.refCount.Add(1)
}

func (s *sharedStore) Release() error {
if s.refCount.Dec() == 0 && s.tryUnregister() {
if s.refCount.Add(-1) == 0 && s.tryUnregister() {
return s.backend.Close()
}
return nil
Expand Down
Loading