Skip to content

Commit

Permalink
Synchronize write access to Hashtables in LicenseManager (#300)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephentoub authored Nov 26, 2019
1 parent bf88f14 commit 056565d
Showing 1 changed file with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Reflection;
using System.Diagnostics;
using System.Collections;
using System.ComponentModel.Design;
using System.Diagnostics;
using System.Reflection;
using System.Threading;

namespace System.ComponentModel
{
Expand Down Expand Up @@ -87,17 +88,26 @@ private static void CacheProvider(Type type, LicenseProvider provider)
{
if (s_providers == null)
{
s_providers = new Hashtable();
Interlocked.CompareExchange(ref s_providers, new Hashtable(), null);
}

lock (s_providers)
{
s_providers[type] = provider;
}
s_providers[type] = provider;

if (provider != null)
{
if (s_providerInstances == null)
{
s_providerInstances = new Hashtable();
Interlocked.CompareExchange(ref s_providerInstances, new Hashtable(), null);
}

Type providerType = provider.GetType();
lock (s_providerInstances)
{
s_providerInstances[providerType] = provider;
}
s_providerInstances[provider.GetType()] = provider;
}
}

Expand Down

0 comments on commit 056565d

Please sign in to comment.