Skip to content

Commit

Permalink
added lock for instruments array
Browse files Browse the repository at this point in the history
  • Loading branch information
DNVindhya committed Apr 26, 2024
1 parent 2dbf553 commit 5f98cdf
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions api/src/main/java/io/grpc/MetricInstrumentRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ public final class MetricInstrumentRegistry {
static final int INITIAL_INSTRUMENT_CAPACITY = 5;
private static MetricInstrumentRegistry instance;
private final Object lock = new Object();
@GuardedBy("lock")
private final Set<String> registeredMetricNames = new HashSet<>();
private volatile MetricInstrument[] metricInstruments =
@GuardedBy("lock")
private MetricInstrument[] metricInstruments =
new MetricInstrument[INITIAL_INSTRUMENT_CAPACITY];
@GuardedBy("lock")
private int nextAvailableMetricIndex;
Expand Down Expand Up @@ -262,7 +264,8 @@ public LongGaugeMetricInstrument registerLongGauge(String name, String descripti
}
}

private synchronized void resizeMetricInstruments() {
@GuardedBy("lock")
private void resizeMetricInstruments() {
// Increase the capacity of the metricInstruments array by INITIAL_INSTRUMENT_CAPACITY
int newInstrumentsCapacity = metricInstruments.length + INITIAL_INSTRUMENT_CAPACITY;
MetricInstrument[] resizedMetricInstruments = Arrays.copyOf(metricInstruments,
Expand Down

0 comments on commit 5f98cdf

Please sign in to comment.