Skip to content

Commit

Permalink
refactor: replace custom go-concert atomic types with stdlib atomic (#…
Browse files Browse the repository at this point in the history
…39980)

Co-authored-by: Pierre HILBERT <pierre.hilbert@elastic.co>
  • Loading branch information
kruskall and pierrehilbert committed Jun 24, 2024
1 parent 40bfa06 commit 345e6f3
Showing 1 changed file with 9 additions and 6 deletions.
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

0 comments on commit 345e6f3

Please sign in to comment.