Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
Merge pull request #2729 from JonHanna/fix_2727
Browse files Browse the repository at this point in the history
Ensure same lock is used to read and write Dictionary in AppContext
  • Loading branch information
AlexGhiondea committed Jan 20, 2016
2 parents 76f9db8 + 5845a94 commit b8a59ae
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/mscorlib/src/System/AppContext/AppContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ private enum SwitchValueState
HasLookedForOverride = 0x4,
UnknownValue = 0x8 // Has no default and could not find an override
}
private static Dictionary<string, SwitchValueState> s_switchMap = new Dictionary<string, SwitchValueState>();
private static readonly object s_syncLock = new object();
private static readonly Dictionary<string, SwitchValueState> s_switchMap = new Dictionary<string, SwitchValueState>();

public static string BaseDirectory
{
Expand Down Expand Up @@ -157,11 +156,13 @@ public static void SetSwitch(string switchName, bool isEnabled)
if (switchName.Length == 0)
throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "switchName");

lock (s_syncLock)
SwitchValueState switchValue = (isEnabled ? SwitchValueState.HasTrueValue : SwitchValueState.HasFalseValue)
| SwitchValueState.HasLookedForOverride;

lock (s_switchMap)
{
// Store the new value and the fact that we checked in the dictionary
s_switchMap[switchName] = (isEnabled ? SwitchValueState.HasTrueValue : SwitchValueState.HasFalseValue)
| SwitchValueState.HasLookedForOverride;
s_switchMap[switchName] = switchValue;
}
}

Expand Down

0 comments on commit b8a59ae

Please sign in to comment.