From 5845a94d9e1b27f294e2d183414244bfecb02d47 Mon Sep 17 00:00:00 2001 From: Jon Hanna Date: Tue, 19 Jan 2016 19:11:22 +0000 Subject: [PATCH] Ensure same lock is used to read and write Dictionary in AppContext Fixes #2727 --- src/mscorlib/src/System/AppContext/AppContext.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/mscorlib/src/System/AppContext/AppContext.cs b/src/mscorlib/src/System/AppContext/AppContext.cs index 30a405d..ecd85d3 100644 --- a/src/mscorlib/src/System/AppContext/AppContext.cs +++ b/src/mscorlib/src/System/AppContext/AppContext.cs @@ -16,8 +16,7 @@ namespace System HasLookedForOverride = 0x4, UnknownValue = 0x8 // Has no default and could not find an override } - private static Dictionary s_switchMap = new Dictionary(); - private static readonly object s_syncLock = new object(); + private static readonly Dictionary s_switchMap = new Dictionary(); public static string BaseDirectory { @@ -157,11 +156,13 @@ namespace System 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; } } -- 2.7.4