Skip to content

Commit ccafba9

Browse files
authored
Use a static lock to access the static Instances dictionary (#80)
1 parent 8c282ae commit ccafba9

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/prometheus-net.DotNetRuntime/DotNetRuntimeStatsCollector.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ internal sealed class DotNetRuntimeStatsCollector :
2020

2121
private readonly CollectorRegistry _metricRegistry;
2222
private readonly Options _options;
23-
private readonly object _lockInstance = new ();
23+
private static readonly object LockInstance = new ();
2424
private readonly CancellationTokenSource _ctSource = new();
2525
private readonly Task _recycleTask;
2626
private bool _disposed = false;
@@ -34,7 +34,7 @@ internal DotNetRuntimeStatsCollector(ServiceProvider serviceProvider, CollectorR
3434
var metrics = Prometheus.Metrics.WithCustomRegistry(_metricRegistry);
3535
_listenerGlobalOpts = DotNetEventListener.GlobalOptions.CreateFrom(_options, metrics);
3636

37-
lock (_lockInstance)
37+
lock (LockInstance)
3838
{
3939
if (Instances.ContainsKey(_metricRegistry))
4040
{
@@ -143,7 +143,7 @@ public void Dispose()
143143
}
144144
finally
145145
{
146-
lock (_lockInstance)
146+
lock (LockInstance)
147147
{
148148
Instances.Remove(_metricRegistry);
149149
}

0 commit comments

Comments
 (0)