Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a static lock to access the static Instances dictionary #80

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal sealed class DotNetRuntimeStatsCollector :

private readonly CollectorRegistry _metricRegistry;
private readonly Options _options;
private readonly object _lockInstance = new ();
private static readonly object LockInstance = new ();
private readonly CancellationTokenSource _ctSource = new();
private readonly Task _recycleTask;
private bool _disposed = false;
Expand All @@ -34,7 +34,7 @@ internal DotNetRuntimeStatsCollector(ServiceProvider serviceProvider, CollectorR
var metrics = Prometheus.Metrics.WithCustomRegistry(_metricRegistry);
_listenerGlobalOpts = DotNetEventListener.GlobalOptions.CreateFrom(_options, metrics);

lock (_lockInstance)
lock (LockInstance)
{
if (Instances.ContainsKey(_metricRegistry))
{
Expand Down Expand Up @@ -143,7 +143,7 @@ public void Dispose()
}
finally
{
lock (_lockInstance)
lock (LockInstance)
{
Instances.Remove(_metricRegistry);
}
Expand Down
Loading