[#411] Remove unnecessary pointers for sync objects

Signed-off-by: Alejandro Lopez <a.lopez@yadro.com>
This commit is contained in:
Alejandro Lopez 2023-05-30 10:14:37 +03:00 committed by Evgenii Stratonikov
parent f934abed8f
commit faca861451
20 changed files with 39 additions and 64 deletions

View file

@ -25,19 +25,18 @@ type valueWithTime[V any] struct {
}
type locker struct {
mtx *sync.Mutex
mtx sync.Mutex
waiters int // not protected by mtx, must used outer mutex to update concurrently
}
type keyLocker[K comparable] struct {
lockers map[K]*locker
lockersMtx *sync.Mutex
lockersMtx sync.Mutex
}
func newKeyLocker[K comparable]() *keyLocker[K] {
return &keyLocker[K]{
lockers: make(map[K]*locker),
lockersMtx: &sync.Mutex{},
}
}
@ -53,7 +52,6 @@ func (l *keyLocker[K]) LockKey(key K) {
}
locker := &locker{
mtx: &sync.Mutex{},
waiters: 1,
}
locker.mtx.Lock()

View file

@ -327,7 +327,7 @@ type internals struct {
log *logger.Logger
wg *sync.WaitGroup
wg sync.WaitGroup
workers []worker
closers []closer
@ -589,7 +589,6 @@ func initInternals(appCfg *config.Config, log *logger.Logger) internals {
appCfg: appCfg,
internalErr: make(chan error),
log: log,
wg: new(sync.WaitGroup),
apiVersion: version.Current(),
healthStatus: &healthStatus,
}

View file

@ -49,7 +49,7 @@ type (
Processor struct {
parsedWallets []util.Uint160
// protects parsedWallets from concurrent change
pwLock *sync.RWMutex
pwLock sync.RWMutex
log *logger.Logger
metrics metrics.Register
pool *ants.Pool
@ -99,7 +99,6 @@ func New(p *Params) (*Processor, error) {
return &Processor{
parsedWallets: p.ParsedWallets,
pwLock: new(sync.RWMutex),
log: p.Log,
metrics: metricsRegister,
pool: pool,

View file

@ -68,7 +68,7 @@ type (
epochState EpochState
alphabetState AlphabetState
converter PrecisionConverter
mintEmitLock *sync.Mutex
mintEmitLock sync.Mutex
mintEmitCache *lru.Cache[string, uint64]
mintEmitThreshold uint64
mintEmitValue fixedn.Fixed8
@ -148,7 +148,6 @@ func New(p *Params) (*Processor, error) {
epochState: p.EpochState,
alphabetState: p.AlphabetState,
converter: p.Converter,
mintEmitLock: new(sync.Mutex),
mintEmitCache: lruCache,
mintEmitThreshold: p.MintEmitThreshold,
mintEmitValue: p.MintEmitValue,

View file

@ -9,7 +9,7 @@ import (
type (
cleanupTable struct {
*sync.RWMutex
sync.RWMutex
enabled bool
threshold uint64
lastAccess map[string]epochStampWithNodeInfo
@ -29,7 +29,6 @@ type (
func newCleanupTable(enabled bool, threshold uint64) cleanupTable {
return cleanupTable{
RWMutex: new(sync.RWMutex),
enabled: enabled,
threshold: threshold,
lastAccess: make(map[string]epochStampWithNodeInfo),

View file

@ -20,7 +20,7 @@ type StorageEngine struct {
removeDuplicatesInProgress atomic.Bool
mtx *sync.RWMutex
mtx sync.RWMutex
shards map[string]hashedShard
@ -226,14 +226,11 @@ func New(opts ...Option) *StorageEngine {
return &StorageEngine{
cfg: c,
mtx: new(sync.RWMutex),
shards: make(map[string]hashedShard),
shardPools: make(map[string]util.WorkerPool),
closeCh: make(chan struct{}),
setModeCh: make(chan setModeRequest),
evacuateLimiter: &evacuationLimiter{
guard: &sync.RWMutex{},
},
evacuateLimiter: &evacuationLimiter{},
}
}

View file

@ -113,7 +113,7 @@ type evacuationLimiter struct {
eg *errgroup.Group
cancel context.CancelFunc
guard *sync.RWMutex
guard sync.RWMutex
}
func (l *evacuationLimiter) TryStart(ctx context.Context, shardIDs []string, result *EvacuateShardRes) (*errgroup.Group, context.Context, error) {

View file

@ -66,7 +66,7 @@ type Client struct {
// switchLock protects endpoints, inactive, and subscription-related fields.
// It is taken exclusively during endpoint switch and locked in shared mode
// on every normal call.
switchLock *sync.RWMutex
switchLock sync.RWMutex
// channel for internal stop
closeChan chan struct{}
@ -83,7 +83,7 @@ type Client struct {
}
type cache struct {
m *sync.RWMutex
m sync.RWMutex
nnsHash *util.Uint160
gKey *keys.PublicKey

View file

@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
"sync"
"time"
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
@ -110,7 +109,6 @@ func New(ctx context.Context, key *keys.PrivateKey, opts ...Option) (*Client, er
acc: acc,
accAddr: accAddr,
cfg: *cfg,
switchLock: &sync.RWMutex{},
closeChan: make(chan struct{}),
}
@ -198,7 +196,6 @@ func newActor(ws *rpcclient.WSClient, acc *wallet.Account, cfg cfg) (*actor.Acto
func newClientCache() cache {
c, _ := lru.New[util.Uint256, uint32](100) // returns error only if size is negative
return cache{
m: &sync.RWMutex{},
txHeights: c,
}
}

View file

@ -42,7 +42,7 @@ type (
}
subscriber struct {
*sync.RWMutex
sync.RWMutex
log *logger.Logger
client *client.Client
@ -163,7 +163,6 @@ func New(ctx context.Context, p *Params) (Subscriber, error) {
}
sub := &subscriber{
RWMutex: new(sync.RWMutex),
log: p.Log,
client: p.Client,
notifyChan: make(chan *state.ContainedNotificationEvent),

View file

@ -17,7 +17,7 @@ type BlockTickHandler func()
type BlockTimer struct {
rolledBack bool
mtx *sync.Mutex
mtx sync.Mutex
dur BlockMeter
@ -64,7 +64,6 @@ func StaticBlockMeter(d uint32) BlockMeter {
// Reset should be called before timer ticking.
func NewBlockTimer(dur BlockMeter, h BlockTickHandler) *BlockTimer {
return &BlockTimer{
mtx: new(sync.Mutex),
dur: dur,
mul: 1,
div: 1,
@ -80,7 +79,6 @@ func NewBlockTimer(dur BlockMeter, h BlockTickHandler) *BlockTimer {
// Do not use delta handlers with pulse in this timer.
func NewOneTickTimer(dur BlockMeter, h BlockTickHandler) *BlockTimer {
return &BlockTimer{
mtx: new(sync.Mutex),
dur: dur,
mul: 1,
div: 1,

View file

@ -25,7 +25,7 @@ type Writer struct {
js nats.JetStreamContext
nc *nats.Conn
m *sync.RWMutex
m sync.RWMutex
createdStreams map[string]struct{}
opts
}
@ -84,7 +84,6 @@ func (n *Writer) Notify(topic string, address oid.Address) error {
// New creates new Writer.
func New(oo ...Option) *Writer {
w := &Writer{
m: &sync.RWMutex{},
createdStreams: make(map[string]struct{}),
opts: opts{
log: &logger.Logger{Logger: zap.L()},

View file

@ -23,8 +23,8 @@ import (
)
type getRequestForwarder struct {
OnceResign *sync.Once
OnceHeaderSending *sync.Once
OnceResign sync.Once
OnceHeaderSending sync.Once
GlobalProgress int
Key *ecdsa.PrivateKey
Request *objectV2.GetRequest

View file

@ -23,7 +23,7 @@ import (
)
type getRangeRequestForwarder struct {
OnceResign *sync.Once
OnceResign sync.Once
GlobalProgress int
Key *ecdsa.PrivateKey
Request *objectV2.GetRangeRequest

View file

@ -25,7 +25,7 @@ import (
type headRequestForwarder struct {
Request *objectV2.HeadRequest
Response *objectV2.HeadResponse
OnceResign *sync.Once
OnceResign sync.Once
ObjectAddr oid.Address
Key *ecdsa.PrivateKey
}

View file

@ -5,7 +5,6 @@ import (
"crypto/sha256"
"errors"
"hash"
"sync"
objectV2 "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object"
"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/refs"
@ -59,8 +58,6 @@ func (s *Service) toPrm(req *objectV2.GetRequest, stream objectSvc.GetObjectStre
}
forwarder := &getRequestForwarder{
OnceResign: &sync.Once{},
OnceHeaderSending: &sync.Once{},
GlobalProgress: 0,
Key: key,
Request: req,
@ -115,7 +112,6 @@ func (s *Service) toRangePrm(req *objectV2.GetRangeRequest, stream objectSvc.Get
}
forwarder := &getRangeRequestForwarder{
OnceResign: &sync.Once{},
GlobalProgress: 0,
Key: key,
Request: req,
@ -254,7 +250,6 @@ func (s *Service) toHeadPrm(req *objectV2.HeadRequest, resp *objectV2.HeadRespon
forwarder := &headRequestForwarder{
Request: req,
Response: resp,
OnceResign: &sync.Once{},
ObjectAddr: objAddr,
Key: key,
}

View file

@ -20,7 +20,7 @@ import (
)
type requestForwarder struct {
OnceResign *sync.Once
OnceResign sync.Once
Request *objectV2.SearchRequest
Key *ecdsa.PrivateKey
}

View file

@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
"sync"
objectV2 "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/client"
@ -51,7 +50,6 @@ func (s *Service) toPrm(req *objectV2.SearchRequest, stream objectSvc.SearchStre
}
forwarder := &requestForwarder{
OnceResign: &sync.Once{},
Request: req,
Key: key,
}

View file

@ -29,7 +29,7 @@ type Option func(*cfg)
// Traverser represents utility for controlling
// traversal of object placement vectors.
type Traverser struct {
mtx *sync.RWMutex
mtx sync.RWMutex
vectors [][]netmap.NodeInfo
@ -107,7 +107,6 @@ func NewTraverser(opts ...Option) (*Traverser, error) {
}
return &Traverser{
mtx: new(sync.RWMutex),
rem: rem,
vectors: ns,
}, nil

View file

@ -18,7 +18,7 @@ type key struct {
// expiring (removing) session tokens.
// Must be created only via calling NewTokenStore.
type TokenStore struct {
mtx *sync.RWMutex
mtx sync.RWMutex
tokens map[key]*storage.PrivateToken
}
@ -28,7 +28,6 @@ type TokenStore struct {
// The elements of the instance are stored in the map.
func NewTokenStore() *TokenStore {
return &TokenStore{
mtx: new(sync.RWMutex),
tokens: make(map[key]*storage.PrivateToken),
}
}