Skip to content

Commit

Permalink
refactor: name mutexes consistently (#2820)
Browse files Browse the repository at this point in the history
Followup on #2819

Signed-off-by: Alexander Yastrebov <[email protected]>
  • Loading branch information
AlexanderYastrebov authored Jan 3, 2024
1 parent 2f067f2 commit be980b8
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 38 deletions.
10 changes: 5 additions & 5 deletions circuit/ratebreaker.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

type rateBreaker struct {
settings BreakerSettings
mx sync.Mutex
mu sync.Mutex
sampler *binarySampler
gb *gobreaker.TwoStepCircuitBreaker
}
Expand All @@ -39,8 +39,8 @@ func newRate(s BreakerSettings) *rateBreaker {
}

func (b *rateBreaker) readyToTrip() bool {
b.mx.Lock()
defer b.mx.Unlock()
b.mu.Lock()
defer b.mu.Unlock()

if b.sampler == nil {
return false
Expand All @@ -51,8 +51,8 @@ func (b *rateBreaker) readyToTrip() bool {

// count the failures in closed and half-open state
func (b *rateBreaker) countRate(success bool) {
b.mx.Lock()
defer b.mx.Unlock()
b.mu.Lock()
defer b.mu.Unlock()

if b.sampler == nil {
b.sampler = newBinarySampler(b.settings.Window)
Expand Down
6 changes: 3 additions & 3 deletions circuit/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ const DefaultIdleTTL = time.Hour
type Registry struct {
defaults BreakerSettings
hostSettings map[string]BreakerSettings
mu sync.Mutex
lookup map[BreakerSettings]*Breaker
mx sync.Mutex
}

// NewRegistry initializes a registry with the provided default settings. Settings with an empty Host field are
Expand Down Expand Up @@ -71,8 +71,8 @@ func (r *Registry) dropIdle(now time.Time) {
}

func (r *Registry) get(s BreakerSettings) *Breaker {
r.mx.Lock()
defer r.mx.Unlock()
r.mu.Lock()
defer r.mu.Unlock()

now := time.Now()

Expand Down
6 changes: 3 additions & 3 deletions filters/diag/diag.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const (
)

type random struct {
mx sync.Mutex
mu sync.Mutex
rand *rand.Rand
len int64
}
Expand Down Expand Up @@ -232,8 +232,8 @@ func (r *random) CreateFilter(args []interface{}) (filters.Filter, error) {
}

func (r *random) Read(p []byte) (int, error) {
r.mx.Lock()
defer r.mx.Unlock()
r.mu.Lock()
defer r.mu.Unlock()
for i := 0; i < len(p); i++ {
p[i] = randomChars[r.rand.Intn(len(randomChars))]
}
Expand Down
6 changes: 3 additions & 3 deletions loadbalancer/algorithm.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ func noSkippedEndpoints(_ int) bool {
}

type powerOfRandomNChoices struct {
mx sync.Mutex
mu sync.Mutex
rnd *rand.Rand
numberOfChoices int
}
Expand All @@ -357,8 +357,8 @@ func newPowerOfRandomNChoices([]string) routing.LBAlgorithm {
func (p *powerOfRandomNChoices) Apply(ctx *routing.LBContext) routing.LBEndpoint {
ne := len(ctx.LBEndpoints)

p.mx.Lock()
defer p.mx.Unlock()
p.mu.Lock()
defer p.mu.Unlock()

best := ctx.LBEndpoints[p.rnd.Intn(ne)]

Expand Down
14 changes: 7 additions & 7 deletions proxy/fadeintesting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ type fadeInProxyInstance struct {

type fadeInProxy struct {
test *testing.T
mx sync.Mutex
mu sync.Mutex
backend *fadeInBackend
instances []*fadeInProxyInstance
}
Expand Down Expand Up @@ -256,8 +256,8 @@ func startProxy(t *testing.T, b *fadeInBackend) *fadeInProxy {
}

func (p *fadeInProxy) addInstances(n int) {
p.mx.Lock()
defer p.mx.Unlock()
p.mu.Lock()
defer p.mu.Unlock()

for i := 0; i < n; i++ {
client := p.backend.createDataClient()
Expand Down Expand Up @@ -290,8 +290,8 @@ func (p *fadeInProxy) addInstances(n int) {
}

func (p *fadeInProxy) endpoints() []string {
p.mx.Lock()
defer p.mx.Unlock()
p.mu.Lock()
defer p.mu.Unlock()

var ep []string
for _, i := range p.instances {
Expand All @@ -302,8 +302,8 @@ func (p *fadeInProxy) endpoints() []string {
}

func (p *fadeInProxy) close() {
p.mx.Lock()
defer p.mx.Unlock()
p.mu.Lock()
defer p.mu.Unlock()

for _, i := range p.instances {
i.close()
Expand Down
24 changes: 12 additions & 12 deletions proxy/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ type (
)

type syncResponseWriter struct {
mx sync.Mutex
mu sync.Mutex
statusCode int
header http.Header
body *bytes.Buffer
Expand All @@ -76,7 +76,7 @@ type listener struct {
}

type testLog struct {
m sync.Mutex
mu sync.Mutex

buf bytes.Buffer
oldOut io.Writer
Expand All @@ -94,15 +94,15 @@ func NewTestLog() *testLog {
}

func (l *testLog) Write(p []byte) (int, error) {
l.m.Lock()
defer l.m.Unlock()
l.mu.Lock()
defer l.mu.Unlock()

return l.buf.Write(p)
}

func (l *testLog) String() string {
l.m.Lock()
defer l.m.Unlock()
l.mu.Lock()
defer l.mu.Unlock()

return l.buf.String()
}
Expand Down Expand Up @@ -178,22 +178,22 @@ func (srw *syncResponseWriter) WriteHeader(statusCode int) {
}

func (srw *syncResponseWriter) Write(b []byte) (int, error) {
srw.mx.Lock()
defer srw.mx.Unlock()
srw.mu.Lock()
defer srw.mu.Unlock()
return srw.body.Write(b)
}

func (srw *syncResponseWriter) Read(b []byte) (int, error) {
srw.mx.Lock()
defer srw.mx.Unlock()
srw.mu.Lock()
defer srw.mu.Unlock()
return srw.body.Read(b)
}

func (srw *syncResponseWriter) Flush() {}

func (srw *syncResponseWriter) Len() int {
srw.mx.Lock()
defer srw.mx.Unlock()
srw.mu.Lock()
defer srw.mu.Unlock()
return srw.body.Len()
}

Expand Down
10 changes: 5 additions & 5 deletions secrets/certregistry/certregistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
// CertRegistry object holds TLS certificates to be used to terminate TLS connections
// ensuring synchronized access to them.
type CertRegistry struct {
mu sync.Mutex
lookup map[string]*tls.Certificate
mx sync.Mutex
}

// NewCertRegistry initializes the certificate registry.
Expand All @@ -38,8 +38,8 @@ func (r *CertRegistry) ConfigureCertificate(host string, cert *tls.Certificate)
}
cert.Leaf = leaf

r.mx.Lock()
defer r.mx.Unlock()
r.mu.Lock()
defer r.mu.Unlock()

curr, found := r.lookup[host]
if found {
Expand All @@ -60,9 +60,9 @@ func (r *CertRegistry) ConfigureCertificate(host string, cert *tls.Certificate)
// GetCertFromHello reads the SNI from a TLS client and returns the appropriate certificate.
// If no certificate is found for the host it will return nil.
func (r *CertRegistry) GetCertFromHello(hello *tls.ClientHelloInfo) (*tls.Certificate, error) {
r.mx.Lock()
r.mu.Lock()
cert, found := r.lookup[hello.ServerName]
r.mx.Unlock()
r.mu.Unlock()
if found {
return cert, nil
}
Expand Down

0 comments on commit be980b8

Please sign in to comment.