It used to be that the CS0420 warning ("a reference to a volatile field will not be treated as volatile") would fire when a volatile was used with an Interlocked.* operation. That warning was unnecessary, as Interlocked.* would itself provide the relevant barriers, and these functions were special cased in Roslyn a long time ago. But there are still lots of places where pragmas disabling the warning have stuck around. I'm deleting them all.
Commit migrated from https://github.com/dotnet/coreclr/commit/
7ca73bcfa0ce072617b068393b7ed66919097bc1
//
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-#pragma warning disable 0420
-
using System.Diagnostics;
using System.Runtime.ExceptionServices;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using System.Runtime.ExceptionServices;
-// Disable the "reference to volatile field not treated as volatile" error.
-#pragma warning disable 0420
-
namespace System.Threading.Tasks
{
/// <summary>
using Thread = Internal.Runtime.Augments.RuntimeThread;
#endif
-// Disable the "reference to volatile field not treated as volatile" error.
-#pragma warning disable 0420
-
namespace System.Threading.Tasks
{
/// <summary>
using System.Runtime.ExceptionServices;
using System.Threading;
-// Disable the "reference to volatile field not treated as volatile" error.
-#pragma warning disable 0420
-
namespace System.Threading.Tasks
{
/// <summary>
//
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-// Disable the "reference to volatile field not treated as volatile" error.
-#pragma warning disable 0420
-
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
// This file contains the primary interface and management of tasks and queues.
//
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-// Disable the "reference to volatile field not treated as volatile" error.
-#pragma warning disable 0420
using System.Collections.Generic;
using System.Diagnostics;
private const int MaxKeyLength = 255;
-#pragma warning disable 0420
private sealed partial class CachedData
{
private static TimeZoneInfo GetCurrentOneYearLocal()
return oneYearLocFromUtc;
}
}
-#pragma warning restore 0420
private sealed class OffsetAndRule
{
// For example, TimeZoneInfo.Local can be cleared by another thread calling TimeZoneInfo.ClearCachedData. Without the consistent snapshot,
// there is a chance that the internal ConvertTime calls will throw since 'source' won't be reference equal to the new TimeZoneInfo.Local.
//
-#pragma warning disable 0420
private sealed partial class CachedData
{
private volatile TimeZoneInfo _localTimeZone;
public ReadOnlyCollection<TimeZoneInfo> _readOnlySystemTimeZones;
public bool _allSystemTimeZonesRead;
};
-#pragma warning restore 0420
// used by GetUtcOffsetFromUtc (DateTime.Now, DateTime.ToLocalTime) for max/min whole-day range checks
private static readonly DateTime s_maxDateOnly = new DateTime(9999, 12, 31);