Skip to content

Commit

Permalink
Get rid of mutex in favor of atomic operations.
Browse files Browse the repository at this point in the history
  • Loading branch information
keep94 committed Nov 18, 2021
1 parent 9974cc5 commit 21ed322
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions exporter/tanzuobservabilityexporter/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"context"
"errors"
"fmt"
"sync"
"sync/atomic"

"go.opentelemetry.io/collector/model/pdata"
"go.uber.org/multierr"
Expand Down Expand Up @@ -142,7 +142,6 @@ type flushCloser interface {

// counter represents an internal counter metric. The zero value is ready to use
type counter struct {
lock sync.Mutex
count int64
}

Expand All @@ -159,16 +158,12 @@ func (c *counter) Report(

// Inc increments this counter by one.
func (c *counter) Inc() {
c.lock.Lock()
defer c.lock.Unlock()
c.count++
atomic.AddInt64(&c.count, 1)
}

// Get gets the value of this counter.
func (c *counter) Get() int64 {
c.lock.Lock()
defer c.lock.Unlock()
return c.count
return atomic.LoadInt64(&c.count)
}

// logMissingValue keeps track of metrics with missing values. metric is the
Expand Down

0 comments on commit 21ed322

Please sign in to comment.