From 28408bb7a98501a8dca5bbd320dc7f6bab24e9f5 Mon Sep 17 00:00:00 2001 From: CarolWang Date: Wed, 6 Jul 2022 02:25:03 -0700 Subject: [PATCH 01/10] Add setter to TransactionManager.DefaultTimeout and MaxTimeout. --- .../ref/System.Transactions.Local.cs | 4 +- .../System/Transactions/TransactionManager.cs | 48 ++++++++++++++++- .../System.Transactions.Local.Tests.csproj | 1 + .../tests/TransactionManagerTest.cs | 52 +++++++++++++++++++ 4 files changed, 102 insertions(+), 3 deletions(-) create mode 100644 src/libraries/System.Transactions.Local/tests/TransactionManagerTest.cs diff --git a/src/libraries/System.Transactions.Local/ref/System.Transactions.Local.cs b/src/libraries/System.Transactions.Local/ref/System.Transactions.Local.cs index f52ae1ffd8b91..2f08b176bc27b 100644 --- a/src/libraries/System.Transactions.Local/ref/System.Transactions.Local.cs +++ b/src/libraries/System.Transactions.Local/ref/System.Transactions.Local.cs @@ -187,10 +187,10 @@ public static partial class TransactionInterop } public static partial class TransactionManager { - public static System.TimeSpan DefaultTimeout { get { throw null; } } + public static System.TimeSpan DefaultTimeout { get { throw null; } set { } } [System.Diagnostics.CodeAnalysis.DisallowNullAttribute] public static System.Transactions.HostCurrentTransactionCallback? HostCurrentCallback { get { throw null; } set { } } - public static System.TimeSpan MaximumTimeout { get { throw null; } } + public static System.TimeSpan MaximumTimeout { get { throw null; } set { } } public static event System.Transactions.TransactionStartedEventHandler? DistributedTransactionStarted { add { } remove { } } public static void RecoveryComplete(System.Guid resourceManagerIdentifier) { } public static System.Transactions.Enlistment Reenlist(System.Guid resourceManagerIdentifier, byte[] recoveryInformation, System.Transactions.IEnlistmentNotification enlistmentNotification) { throw null; } diff --git a/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionManager.cs b/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionManager.cs index c4d3c4ad726a7..0c3b00d090b53 100644 --- a/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionManager.cs +++ b/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionManager.cs @@ -310,6 +310,31 @@ public static TimeSpan DefaultTimeout } return s_defaultTimeout; } + set + { + TransactionsEtwProvider etwLog = TransactionsEtwProvider.Log; + if (etwLog.IsEnabled()) + { + etwLog.MethodEnter(TraceSourceType.TraceSourceBase, "TransactionManager.set_DefaultTimeout"); + } + + s_defaultTimeout = ValidateTimeout(value); + + if (s_defaultTimeout != DefaultSettingsSection.Timeout) + { + if (etwLog.IsEnabled()) + { + etwLog.ConfiguredDefaultTimeoutAdjusted(); + } + } + + s_defaultTimeoutValidated = true; + + if (etwLog.IsEnabled()) + { + etwLog.MethodExit(TraceSourceType.TraceSourceBase, "TransactionManager.set_DefaultTimeout"); + } + } } @@ -325,7 +350,7 @@ public static TimeSpan MaximumTimeout etwLog.MethodEnter(TraceSourceType.TraceSourceBase, "TransactionManager.get_DefaultMaximumTimeout"); } - LazyInitializer.EnsureInitialized(ref s_maximumTimeout, ref s_cachedMaxTimeout, ref s_classSyncObject, () => DefaultSettingsSection.Timeout); + LazyInitializer.EnsureInitialized(ref s_maximumTimeout, ref s_cachedMaxTimeout, ref s_classSyncObject, () => MachineSettingsSection.MaxTimeout); if (etwLog.IsEnabled()) { @@ -334,6 +359,27 @@ public static TimeSpan MaximumTimeout return s_maximumTimeout; } + set + { + TransactionsEtwProvider etwLog = TransactionsEtwProvider.Log; + if (etwLog.IsEnabled()) + { + etwLog.MethodEnter(TraceSourceType.TraceSourceBase, "TransactionManager.set_DefaultMaximumTimeout"); + } + + if(value < TimeSpan.Zero) + { + throw new ArgumentOutOfRangeException(nameof(value)); + } + + s_cachedMaxTimeout = false; + LazyInitializer.EnsureInitialized(ref s_maximumTimeout, ref s_cachedMaxTimeout, ref s_classSyncObject, () => value); + + if (etwLog.IsEnabled()) + { + etwLog.MethodExit(TraceSourceType.TraceSourceBase, "TransactionManager.set_DefaultMaximumTimeout"); + } + } } /// diff --git a/src/libraries/System.Transactions.Local/tests/System.Transactions.Local.Tests.csproj b/src/libraries/System.Transactions.Local/tests/System.Transactions.Local.Tests.csproj index 90c3f0f9742e0..a5dda3d568935 100644 --- a/src/libraries/System.Transactions.Local/tests/System.Transactions.Local.Tests.csproj +++ b/src/libraries/System.Transactions.Local/tests/System.Transactions.Local.Tests.csproj @@ -7,6 +7,7 @@ + diff --git a/src/libraries/System.Transactions.Local/tests/TransactionManagerTest.cs b/src/libraries/System.Transactions.Local/tests/TransactionManagerTest.cs new file mode 100644 index 0000000000000..5a4fdaa22fce3 --- /dev/null +++ b/src/libraries/System.Transactions.Local/tests/TransactionManagerTest.cs @@ -0,0 +1,52 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using Xunit; + +namespace System.Transactions.Tests +{ + public class TransactionManagerTest + { + + [Fact] + public void DefaultTimeout_Set_LessThanMaximum() + { + TimeSpan tsDefault = TimeSpan.Parse("00:02:00"); + TransactionManager.DefaultTimeout = tsDefault; + + Assert.Equal(tsDefault, TransactionManager.DefaultTimeout); + } + + [Fact] + public void DefaultTimeout_Set_ExceedMaximum() + { + TimeSpan ts = TransactionManager.MaximumTimeout.Add(TimeSpan.FromMinutes(10)); + TransactionManager.DefaultTimeout = ts; + + Assert.Equal(TransactionManager.DefaultTimeout, TransactionManager.MaximumTimeout); + } + + [Fact] + public void DefaultTimeout_Set_Negative() + { + TimeSpan ts = TimeSpan.Parse("-00:01:00"); + Assert.Throws(() => TransactionManager.DefaultTimeout = ts); + } + + [Fact] + public void MaximumTimeout_Set_Positive() + { + TimeSpan ts = TimeSpan.Parse("00:30:00"); + TransactionManager.MaximumTimeout = ts; + + Assert.Equal(ts, TransactionManager.MaximumTimeout); + } + + [Fact] + public void MaximumTimeout_Set_Negative() + { + TimeSpan ts = TimeSpan.Parse("-00:10:00"); + Assert.Throws(() => TransactionManager.MaximumTimeout = ts); + } + } +} From 9028801dc62e80b0075cc42148339dd1e3203e68 Mon Sep 17 00:00:00 2001 From: CarolWang Date: Wed, 6 Jul 2022 19:03:20 -0700 Subject: [PATCH 02/10] Address reveiw feedback. --- .../src/System/Transactions/TransactionManager.cs | 8 +++++--- .../tests/TransactionManagerTest.cs | 1 - 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionManager.cs b/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionManager.cs index 0c3b00d090b53..2ed48b17edb11 100644 --- a/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionManager.cs +++ b/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionManager.cs @@ -320,7 +320,7 @@ public static TimeSpan DefaultTimeout s_defaultTimeout = ValidateTimeout(value); - if (s_defaultTimeout != DefaultSettingsSection.Timeout) + if (s_defaultTimeout != value) { if (etwLog.IsEnabled()) { @@ -372,8 +372,10 @@ public static TimeSpan MaximumTimeout throw new ArgumentOutOfRangeException(nameof(value)); } - s_cachedMaxTimeout = false; - LazyInitializer.EnsureInitialized(ref s_maximumTimeout, ref s_cachedMaxTimeout, ref s_classSyncObject, () => value); + s_cachedMaxTimeout = true; + s_maximumTimeout = value; + s_defaultTimeout = ValidateTimeout(s_defaultTimeout); + s_defaultTimeoutValidated = true; if (etwLog.IsEnabled()) { diff --git a/src/libraries/System.Transactions.Local/tests/TransactionManagerTest.cs b/src/libraries/System.Transactions.Local/tests/TransactionManagerTest.cs index 5a4fdaa22fce3..4121342334196 100644 --- a/src/libraries/System.Transactions.Local/tests/TransactionManagerTest.cs +++ b/src/libraries/System.Transactions.Local/tests/TransactionManagerTest.cs @@ -7,7 +7,6 @@ namespace System.Transactions.Tests { public class TransactionManagerTest { - [Fact] public void DefaultTimeout_Set_LessThanMaximum() { From f1df0b907f4fd3640ce5aa3d85dab5aca57d66dd Mon Sep 17 00:00:00 2001 From: CarolWang Date: Sun, 10 Jul 2022 18:05:53 -0700 Subject: [PATCH 03/10] Log event if DefaultTimeout get reduced by setting MaxTimeout. --- .../src/System/Transactions/TransactionManager.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionManager.cs b/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionManager.cs index 2ed48b17edb11..3e1c9418fd77e 100644 --- a/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionManager.cs +++ b/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionManager.cs @@ -374,7 +374,16 @@ public static TimeSpan MaximumTimeout s_cachedMaxTimeout = true; s_maximumTimeout = value; + TimeSpan defaultTimeout = s_defaultTimeout; s_defaultTimeout = ValidateTimeout(s_defaultTimeout); + if (s_defaultTimeout != defaultTimeout) + { + if (etwLog.IsEnabled()) + { + etwLog.ConfiguredDefaultTimeoutAdjusted(); + } + } + s_defaultTimeoutValidated = true; if (etwLog.IsEnabled()) From b375528a7b159cc13ac89bfb68658cb2fcd35d8c Mon Sep 17 00:00:00 2001 From: CarolWang Date: Mon, 11 Jul 2022 00:09:59 -0700 Subject: [PATCH 04/10] Update tests. --- .../tests/TransactionManagerTest.cs | 31 +++++-------------- 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/src/libraries/System.Transactions.Local/tests/TransactionManagerTest.cs b/src/libraries/System.Transactions.Local/tests/TransactionManagerTest.cs index 4121342334196..d31cbea2887b8 100644 --- a/src/libraries/System.Transactions.Local/tests/TransactionManagerTest.cs +++ b/src/libraries/System.Transactions.Local/tests/TransactionManagerTest.cs @@ -8,43 +8,28 @@ namespace System.Transactions.Tests public class TransactionManagerTest { [Fact] - public void DefaultTimeout_Set_LessThanMaximum() + public void DefaultTimeout_MaxTimeout_Set_Get() { TimeSpan tsDefault = TimeSpan.Parse("00:02:00"); - TransactionManager.DefaultTimeout = tsDefault; + TimeSpan tsMax = TimeSpan.Parse("00:30:00"); + TransactionManager.DefaultTimeout = tsDefault; Assert.Equal(tsDefault, TransactionManager.DefaultTimeout); - } - [Fact] - public void DefaultTimeout_Set_ExceedMaximum() - { + TransactionManager.MaximumTimeout = tsMax; + Assert.Equal(tsMax, TransactionManager.MaximumTimeout); + TimeSpan ts = TransactionManager.MaximumTimeout.Add(TimeSpan.FromMinutes(10)); TransactionManager.DefaultTimeout = ts; - + Assert.Equal(tsMax, TransactionManager.MaximumTimeout); Assert.Equal(TransactionManager.DefaultTimeout, TransactionManager.MaximumTimeout); } [Fact] - public void DefaultTimeout_Set_Negative() + public void DefaultTimeout_MaxTimeout_Set_Negative() { TimeSpan ts = TimeSpan.Parse("-00:01:00"); Assert.Throws(() => TransactionManager.DefaultTimeout = ts); - } - - [Fact] - public void MaximumTimeout_Set_Positive() - { - TimeSpan ts = TimeSpan.Parse("00:30:00"); - TransactionManager.MaximumTimeout = ts; - - Assert.Equal(ts, TransactionManager.MaximumTimeout); - } - - [Fact] - public void MaximumTimeout_Set_Negative() - { - TimeSpan ts = TimeSpan.Parse("-00:10:00"); Assert.Throws(() => TransactionManager.MaximumTimeout = ts); } } From 6f37aff22d0fdca2b1500461a67570478700a22f Mon Sep 17 00:00:00 2001 From: CarolWang Date: Mon, 11 Jul 2022 02:55:44 -0700 Subject: [PATCH 05/10] Fix test. --- .../src/System/Transactions/TransactionManager.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionManager.cs b/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionManager.cs index 3e1c9418fd77e..dce15c8f71ef3 100644 --- a/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionManager.cs +++ b/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionManager.cs @@ -374,8 +374,8 @@ public static TimeSpan MaximumTimeout s_cachedMaxTimeout = true; s_maximumTimeout = value; - TimeSpan defaultTimeout = s_defaultTimeout; - s_defaultTimeout = ValidateTimeout(s_defaultTimeout); + TimeSpan defaultTimeout = DefaultTimeout; + s_defaultTimeout = ValidateTimeout(defaultTimeout); if (s_defaultTimeout != defaultTimeout) { if (etwLog.IsEnabled()) From 46d25c86f803586870d8c4b752268eb30d447cb9 Mon Sep 17 00:00:00 2001 From: CarolWang Date: Mon, 11 Jul 2022 03:38:56 -0700 Subject: [PATCH 06/10] Update. --- .../src/System/Transactions/TransactionManager.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionManager.cs b/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionManager.cs index dce15c8f71ef3..b5226bbc44a99 100644 --- a/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionManager.cs +++ b/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionManager.cs @@ -374,8 +374,14 @@ public static TimeSpan MaximumTimeout s_cachedMaxTimeout = true; s_maximumTimeout = value; - TimeSpan defaultTimeout = DefaultTimeout; - s_defaultTimeout = ValidateTimeout(defaultTimeout); + + if(!s_defaultTimeoutValidated) + { + s_defaultTimeout = DefaultSettingsSection.Timeout; + } + + TimeSpan defaultTimeout = s_defaultTimeout; + s_defaultTimeout = ValidateTimeout(s_defaultTimeout); if (s_defaultTimeout != defaultTimeout) { if (etwLog.IsEnabled()) From 5a9e2acd691188e55dcf55979678b01b826e91fc Mon Sep 17 00:00:00 2001 From: CarolWang Date: Mon, 11 Jul 2022 17:37:13 -0700 Subject: [PATCH 07/10] Format and re-org test. --- .../src/System/Transactions/TransactionManager.cs | 4 ++-- .../tests/TransactionManagerTest.cs | 8 ++------ 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionManager.cs b/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionManager.cs index b5226bbc44a99..19fb511dccd13 100644 --- a/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionManager.cs +++ b/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionManager.cs @@ -367,7 +367,7 @@ public static TimeSpan MaximumTimeout etwLog.MethodEnter(TraceSourceType.TraceSourceBase, "TransactionManager.set_DefaultMaximumTimeout"); } - if(value < TimeSpan.Zero) + if (value < TimeSpan.Zero) { throw new ArgumentOutOfRangeException(nameof(value)); } @@ -375,7 +375,7 @@ public static TimeSpan MaximumTimeout s_cachedMaxTimeout = true; s_maximumTimeout = value; - if(!s_defaultTimeoutValidated) + if (!s_defaultTimeoutValidated) { s_defaultTimeout = DefaultSettingsSection.Timeout; } diff --git a/src/libraries/System.Transactions.Local/tests/TransactionManagerTest.cs b/src/libraries/System.Transactions.Local/tests/TransactionManagerTest.cs index d31cbea2887b8..0088b05734a32 100644 --- a/src/libraries/System.Transactions.Local/tests/TransactionManagerTest.cs +++ b/src/libraries/System.Transactions.Local/tests/TransactionManagerTest.cs @@ -23,12 +23,8 @@ public void DefaultTimeout_MaxTimeout_Set_Get() TransactionManager.DefaultTimeout = ts; Assert.Equal(tsMax, TransactionManager.MaximumTimeout); Assert.Equal(TransactionManager.DefaultTimeout, TransactionManager.MaximumTimeout); - } - - [Fact] - public void DefaultTimeout_MaxTimeout_Set_Negative() - { - TimeSpan ts = TimeSpan.Parse("-00:01:00"); + + ts = TimeSpan.Parse("-00:01:00"); Assert.Throws(() => TransactionManager.DefaultTimeout = ts); Assert.Throws(() => TransactionManager.MaximumTimeout = ts); } From 9522b8c0cdf6b51d7f197f08c575b7731eec4f60 Mon Sep 17 00:00:00 2001 From: CarolWang Date: Fri, 22 Jul 2022 02:20:40 -0700 Subject: [PATCH 08/10] Interlocked access timespan to avoid data tear on x86 machine. --- .../System/Transactions/TransactionManager.cs | 30 +++++++------------ .../tests/TransactionManagerTest.cs | 7 ++--- 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionManager.cs b/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionManager.cs index 19fb511dccd13..e556b0b07ce41 100644 --- a/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionManager.cs +++ b/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionManager.cs @@ -279,7 +279,7 @@ internal static IsolationLevel DefaultIsolationLevel private static MachineSettingsSection MachineSettings => s_machineSettings ??= MachineSettingsSection.GetSection(); private static bool s_defaultTimeoutValidated; - private static TimeSpan s_defaultTimeout; + private static long s_defaultTimeoutTicks; public static TimeSpan DefaultTimeout { get @@ -292,23 +292,21 @@ public static TimeSpan DefaultTimeout if (!s_defaultTimeoutValidated) { - s_defaultTimeout = ValidateTimeout(DefaultSettingsSection.Timeout); - // If the timeout value got adjusted, it must have been greater than MaximumTimeout. - if (s_defaultTimeout != DefaultSettingsSection.Timeout) + LazyInitializer.EnsureInitialized(ref s_defaultTimeoutTicks, ref s_defaultTimeoutValidated, ref s_classSyncObject, () => ValidateTimeout(DefaultSettingsSection.Timeout).Ticks); + if (Interlocked.Read(ref s_defaultTimeoutTicks) != DefaultSettingsSection.Timeout.Ticks) { if (etwLog.IsEnabled()) { etwLog.ConfiguredDefaultTimeoutAdjusted(); } } - s_defaultTimeoutValidated = true; } if (etwLog.IsEnabled()) { etwLog.MethodExit(TraceSourceType.TraceSourceBase, "TransactionManager.get_DefaultTimeout"); } - return s_defaultTimeout; + return new TimeSpan(Interlocked.Read(ref s_defaultTimeoutTicks)); } set { @@ -318,9 +316,8 @@ public static TimeSpan DefaultTimeout etwLog.MethodEnter(TraceSourceType.TraceSourceBase, "TransactionManager.set_DefaultTimeout"); } - s_defaultTimeout = ValidateTimeout(value); - - if (s_defaultTimeout != value) + Interlocked.Exchange(ref s_defaultTimeoutTicks, ValidateTimeout(value).Ticks); + if (Interlocked.Read(ref s_defaultTimeoutTicks) != value.Ticks) { if (etwLog.IsEnabled()) { @@ -374,15 +371,12 @@ public static TimeSpan MaximumTimeout s_cachedMaxTimeout = true; s_maximumTimeout = value; + LazyInitializer.EnsureInitialized(ref s_defaultTimeoutTicks, ref s_defaultTimeoutValidated, ref s_classSyncObject, () => DefaultSettingsSection.Timeout.Ticks); - if (!s_defaultTimeoutValidated) - { - s_defaultTimeout = DefaultSettingsSection.Timeout; - } - - TimeSpan defaultTimeout = s_defaultTimeout; - s_defaultTimeout = ValidateTimeout(s_defaultTimeout); - if (s_defaultTimeout != defaultTimeout) + long defaultTimeoutTicks = 0; + Interlocked.Exchange(ref defaultTimeoutTicks, Interlocked.Read(ref s_defaultTimeoutTicks)); + Interlocked.Exchange(ref s_defaultTimeoutTicks, ValidateTimeout(new TimeSpan(Interlocked.Read(ref s_defaultTimeoutTicks))).Ticks); + if (Interlocked.Read(ref s_defaultTimeoutTicks) != Interlocked.Read(ref defaultTimeoutTicks)) { if (etwLog.IsEnabled()) { @@ -390,8 +384,6 @@ public static TimeSpan MaximumTimeout } } - s_defaultTimeoutValidated = true; - if (etwLog.IsEnabled()) { etwLog.MethodExit(TraceSourceType.TraceSourceBase, "TransactionManager.set_DefaultMaximumTimeout"); diff --git a/src/libraries/System.Transactions.Local/tests/TransactionManagerTest.cs b/src/libraries/System.Transactions.Local/tests/TransactionManagerTest.cs index 0088b05734a32..9566901d90db8 100644 --- a/src/libraries/System.Transactions.Local/tests/TransactionManagerTest.cs +++ b/src/libraries/System.Transactions.Local/tests/TransactionManagerTest.cs @@ -11,13 +11,12 @@ public class TransactionManagerTest public void DefaultTimeout_MaxTimeout_Set_Get() { TimeSpan tsDefault = TimeSpan.Parse("00:02:00"); - TimeSpan tsMax = TimeSpan.Parse("00:30:00"); - TransactionManager.DefaultTimeout = tsDefault; Assert.Equal(tsDefault, TransactionManager.DefaultTimeout); - TransactionManager.MaximumTimeout = tsMax; - Assert.Equal(tsMax, TransactionManager.MaximumTimeout); + TimeSpan tsMax = TimeSpan.Parse("00:30:00"); + TransactionManager.MaximumTimeout = tsMax; + Assert.Equal(tsMax, TransactionManager.MaximumTimeout); TimeSpan ts = TransactionManager.MaximumTimeout.Add(TimeSpan.FromMinutes(10)); TransactionManager.DefaultTimeout = ts; From dcfdd510ba4ef460c6703ba5e05cd765d22e2c54 Mon Sep 17 00:00:00 2001 From: CarolWang Date: Mon, 25 Jul 2022 20:32:01 -0700 Subject: [PATCH 09/10] update. --- .../src/System/Transactions/TransactionManager.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionManager.cs b/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionManager.cs index e556b0b07ce41..f24f2318a7f21 100644 --- a/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionManager.cs +++ b/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionManager.cs @@ -373,10 +373,9 @@ public static TimeSpan MaximumTimeout s_maximumTimeout = value; LazyInitializer.EnsureInitialized(ref s_defaultTimeoutTicks, ref s_defaultTimeoutValidated, ref s_classSyncObject, () => DefaultSettingsSection.Timeout.Ticks); - long defaultTimeoutTicks = 0; - Interlocked.Exchange(ref defaultTimeoutTicks, Interlocked.Read(ref s_defaultTimeoutTicks)); + long defaultTimeoutTicks = Interlocked.Read(ref s_defaultTimeoutTicks); Interlocked.Exchange(ref s_defaultTimeoutTicks, ValidateTimeout(new TimeSpan(Interlocked.Read(ref s_defaultTimeoutTicks))).Ticks); - if (Interlocked.Read(ref s_defaultTimeoutTicks) != Interlocked.Read(ref defaultTimeoutTicks)) + if (Interlocked.Read(ref s_defaultTimeoutTicks) != defaultTimeoutTicks) { if (etwLog.IsEnabled()) { From 5a8e0301cb94ea976fca509499c7282f18f848e2 Mon Sep 17 00:00:00 2001 From: CarolWang Date: Mon, 1 Aug 2022 18:24:05 -0700 Subject: [PATCH 10/10] Remove redundant Interlocked.Read. --- .../src/System/Transactions/TransactionManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionManager.cs b/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionManager.cs index f24f2318a7f21..ff811ad32a6de 100644 --- a/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionManager.cs +++ b/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionManager.cs @@ -374,7 +374,7 @@ public static TimeSpan MaximumTimeout LazyInitializer.EnsureInitialized(ref s_defaultTimeoutTicks, ref s_defaultTimeoutValidated, ref s_classSyncObject, () => DefaultSettingsSection.Timeout.Ticks); long defaultTimeoutTicks = Interlocked.Read(ref s_defaultTimeoutTicks); - Interlocked.Exchange(ref s_defaultTimeoutTicks, ValidateTimeout(new TimeSpan(Interlocked.Read(ref s_defaultTimeoutTicks))).Ticks); + Interlocked.Exchange(ref s_defaultTimeoutTicks, ValidateTimeout(new TimeSpan(defaultTimeoutTicks)).Ticks); if (Interlocked.Read(ref s_defaultTimeoutTicks) != defaultTimeoutTicks) { if (etwLog.IsEnabled())