diff --git a/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/BlockingCollection.cs b/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/BlockingCollection.cs index b7dbdb560932d..bf8592946f03e 100644 --- a/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/BlockingCollection.cs +++ b/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/BlockingCollection.cs @@ -461,9 +461,8 @@ private bool TryAddWithNoTimeValidation(T item, int millisecondsTimeout, Cancell while (_currentAdders != COMPLETE_ADDING_ON_MASK) spinner.SpinOnce(); throw new InvalidOperationException(SR.BlockingCollection_Completed); } -#pragma warning disable 0420 // No warning for Interlocked.xxx if compiled with new managed compiler (Roslyn) + if (Interlocked.CompareExchange(ref _currentAdders, observedAdders + 1, observedAdders) == observedAdders) -#pragma warning restore 0420 { Debug.Assert((observedAdders + 1) <= (~COMPLETE_ADDING_ON_MASK), "The number of concurrent adders thread exceeded the maximum limit."); break; @@ -517,9 +516,7 @@ private bool TryAddWithNoTimeValidation(T item, int millisecondsTimeout, Cancell { // decrement the adders count Debug.Assert((_currentAdders & ~COMPLETE_ADDING_ON_MASK) > 0); -#pragma warning disable 0420 // No warning for Interlocked.xxx if compiled with new managed compiler (Roslyn) Interlocked.Decrement(ref _currentAdders); -#pragma warning restore 0420 } } return waitForSemaphoreWasSuccessful; @@ -1489,9 +1486,8 @@ public void CompleteAdding() while (_currentAdders != COMPLETE_ADDING_ON_MASK) spinner.SpinOnce(); return; } -#pragma warning disable 0420 // No warning for Interlocked.xxx if compiled with new managed compiler (Roslyn) + if (Interlocked.CompareExchange(ref _currentAdders, observedAdders | COMPLETE_ADDING_ON_MASK, observedAdders) == observedAdders) -#pragma warning restore 0420 { spinner.Reset(); while (_currentAdders != COMPLETE_ADDING_ON_MASK) spinner.SpinOnce(); diff --git a/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/ConcurrentStack.cs b/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/ConcurrentStack.cs index 67d275b0dd192..cd5d92158d0e6 100644 --- a/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/ConcurrentStack.cs +++ b/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/ConcurrentStack.cs @@ -273,7 +273,6 @@ public void CopyTo(T[] array, int index) ToList().CopyTo(array, index); } -#pragma warning disable 0420 // No warning for Interlocked.xxx if compiled with new managed compiler (Roslyn) /// /// Inserts an object at the top of the . /// @@ -662,7 +661,6 @@ private int TryPopCore(int count, out Node poppedHead) } } } -#pragma warning restore 0420 /// /// Local helper function to copy the popped elements into a given collection diff --git a/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/PartitionerStatic.cs b/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/PartitionerStatic.cs index 8108e51283268..4c8162a1abdc1 100644 --- a/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/PartitionerStatic.cs +++ b/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/PartitionerStatic.cs @@ -630,7 +630,6 @@ IEnumerator IEnumerable.GetEnumerator() return ((InternalPartitionEnumerable)this).GetEnumerator(); } -#pragma warning disable 0420 // No warning for Interlocked.xxx if compiled with new managed compiler (Roslyn) /////////////////// // // Used by GrabChunk_Buffered() @@ -939,8 +938,11 @@ override protected bool GrabNextChunk(int requestedChunkSize) { _localList = new KeyValuePair[_maxChunkSize]; } + +#pragma warning disable 0420 // TODO: https://github.com/dotnet/corefx/issues/35022 // make the actual call to the enumerable that grabs a chunk return _enumerable.GrabChunk(_localList, requestedChunkSize, ref _currentChunkSize.Value); +#pragma warning restore 0420 } /// @@ -987,7 +989,6 @@ override public void Dispose() } } #endregion -#pragma warning restore 0420 } #endregion diff --git a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/AggregateCatalog.cs b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/AggregateCatalog.cs index 4364836a63bd9..1c37f6f2438d9 100644 --- a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/AggregateCatalog.cs +++ b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/AggregateCatalog.cs @@ -181,10 +181,7 @@ protected override void Dispose(bool disposing) { if (disposing) { - // NOTE : According to https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/cs0420, the warning is bogus when used with Interlocked API. -#pragma warning disable 420 if (Interlocked.CompareExchange(ref _isDisposed, 1, 0) == 0) -#pragma warning restore 420 { _catalogs.Dispose(); } diff --git a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/AggregateExportProvider.cs b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/AggregateExportProvider.cs index 9bdfe79e95a66..d82b2fc2abd1d 100644 --- a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/AggregateExportProvider.cs +++ b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/AggregateExportProvider.cs @@ -103,10 +103,7 @@ protected virtual void Dispose(bool disposing) { if (disposing) { - // NOTE : According to https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/cs0420, the warning is bogus when used with Interlocked API. -#pragma warning disable 420 if (Interlocked.CompareExchange(ref _isDisposed, 1, 0) == 0) -#pragma warning restore 420 { foreach (ExportProvider provider in _providers) { diff --git a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/CompositionScopeDefinition.cs b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/CompositionScopeDefinition.cs index e3cf9d858b647..470de40911229 100644 --- a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/CompositionScopeDefinition.cs +++ b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/CompositionScopeDefinition.cs @@ -87,10 +87,7 @@ protected override void Dispose(bool disposing) { if (disposing) { - // NOTE : According to https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/cs0420, the warning is bogus when used with Interlocked API. -#pragma warning disable 420 if (Interlocked.CompareExchange(ref _isDisposed, 1, 0) == 0) -#pragma warning restore 420 { INotifyComposablePartCatalogChanged notifyCatalog = _catalog as INotifyComposablePartCatalogChanged; if (notifyCatalog != null) diff --git a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Primitives/ComposablePartCatalog.cs b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Primitives/ComposablePartCatalog.cs index 3f2b432de9c6e..80ad0aa2b2d6b 100644 --- a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Primitives/ComposablePartCatalog.cs +++ b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Primitives/ComposablePartCatalog.cs @@ -60,10 +60,7 @@ public virtual IQueryable Parts { // Guarantee one time only set _queryableParts var p = this.AsQueryable(); - // NOTE : According to https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/cs0420, the warning is bogus when used with Interlocked API. -#pragma warning disable 420 Interlocked.CompareExchange(ref _queryableParts, p, null); -#pragma warning restore 420 if (_queryableParts == null) { throw new Exception(SR.Diagnostic_InternalExceptionMessage); diff --git a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Primitives/Export.cs b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Primitives/Export.cs index d7f7817ef0d7c..455a19335562d 100644 --- a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Primitives/Export.cs +++ b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Primitives/Export.cs @@ -205,11 +205,7 @@ public object Value if (_exportedValue == Export._EmptyValue) { object exportedValue = GetExportedValueCore(); - - // NOTE : According to https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/cs0420, the warning is bogus when used with Interlocked API. -#pragma warning disable 420 Interlocked.CompareExchange(ref _exportedValue, exportedValue, Export._EmptyValue); -#pragma warning restore 420 } return _exportedValue; diff --git a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/ReflectionModel/DisposableReflectionComposablePart.cs b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/ReflectionModel/DisposableReflectionComposablePart.cs index a00e2477dced5..c6cc44a6e2682 100644 --- a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/ReflectionModel/DisposableReflectionComposablePart.cs +++ b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/ReflectionModel/DisposableReflectionComposablePart.cs @@ -35,10 +35,7 @@ protected override void EnsureRunning() void IDisposable.Dispose() { - // NOTE : According to https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/cs0420, the warning is bogus when used with Interlocked API. -#pragma warning disable 420 if (Interlocked.CompareExchange(ref _isDisposed, 1, 0) == 0) -#pragma warning restore 420 { ReleaseInstanceIfNecessary(CachedInstance); } diff --git a/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/SafeBitVector32.cs b/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/SafeBitVector32.cs index 01882e128195f..7b59fb4313122 100644 --- a/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/SafeBitVector32.cs +++ b/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/SafeBitVector32.cs @@ -32,13 +32,10 @@ internal bool this[int bit] if (value) newData = oldData | bit; else newData = oldData & ~bit; -#pragma warning disable 0420 int result = Interlocked.CompareExchange(ref _data, newData, oldData); -#pragma warning restore 0420 - if (result == oldData) break; } } } } -} \ No newline at end of file +} diff --git a/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/TdsParserStateObject.cs b/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/TdsParserStateObject.cs index 671829dacb2f5..5b3e6a9d3421a 100644 --- a/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/TdsParserStateObject.cs +++ b/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/TdsParserStateObject.cs @@ -2796,8 +2796,6 @@ private void ReadAsyncCallbackCaptureException(TaskCompletionSource sour } } -#pragma warning disable 0420 // a reference to a volatile field will not be treated as volatile - public void WriteAsyncCallback(PacketHandle packet, uint sniError) { WriteAsyncCallback(IntPtr.Zero, packet, sniError); @@ -2885,8 +2883,6 @@ public void WriteAsyncCallback(IntPtr key, PacketHandle packet, uint sniError) } } -#pragma warning restore 0420 - ///////////////////////////////////////// // Network/Packet Writing & Processing // ///////////////////////////////////////// @@ -2923,13 +2919,11 @@ internal void ResetSecurePasswordsInformation() internal Task WaitForAccumulatedWrites() { // Checked for stored exceptions -#pragma warning disable 420 // A reference to a volatile field will not be treated as volatile - Disabling since the Interlocked APIs are volatile aware var delayedException = Interlocked.Exchange(ref _delayedWriteAsyncCallbackException, null); if (delayedException != null) { throw delayedException; } -#pragma warning restore 420 if (_asyncWriteCount == 0) { @@ -2949,13 +2943,11 @@ internal Task WaitForAccumulatedWrites() } // Check for stored exceptions -#pragma warning disable 420 // A reference to a volatile field will not be treated as volatile - Disabling since the Interlocked APIs are volatile aware delayedException = Interlocked.Exchange(ref _delayedWriteAsyncCallbackException, null); if (delayedException != null) { throw delayedException; } -#pragma warning restore 420 // If there are no outstanding writes, see if we can shortcut and return null if ((_asyncWriteCount == 0) && ((!task.IsCompleted) || (task.Exception == null))) @@ -3212,8 +3204,6 @@ private void CancelWritePacket() } } -#pragma warning disable 0420 // a reference to a volatile field will not be treated as volatile - private Task SNIWritePacket(PacketHandle packet, out uint sniError, bool canAccumulate, bool callerHasConnectionLock) { // Check for a stored exception @@ -3351,8 +3341,6 @@ private Task SNIWritePacket(PacketHandle packet, out uint sniError, bool canAccu internal abstract uint WritePacket(PacketHandle packet, bool sync); -#pragma warning restore 0420 - // Sends an attention signal - executing thread will consume attn. internal void SendAttention(bool mustTakeWriteLock = false) { diff --git a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticListener.cs b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticListener.cs index 70e5d4aad5524..ed8fa45aeff9d 100644 --- a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticListener.cs +++ b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticListener.cs @@ -5,12 +5,6 @@ using System.Threading; using System.Collections.Generic; -// TODO when we upgrade to C# V6 you can remove this. -// warning CS0420: 'P.x': a reference to a volatile field will not be treated as volatile -// This happens when you pass a _subcribers (a volatile field) to interlocked operations (which are byref). -// This was fixed in C# V6. -#pragma warning disable 0420 - namespace System.Diagnostics { /// diff --git a/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Channels/AsynchronousChannel.cs b/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Channels/AsynchronousChannel.cs index bf7f7796d3114..6ada687012a74 100644 --- a/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Channels/AsynchronousChannel.cs +++ b/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Channels/AsynchronousChannel.cs @@ -300,9 +300,7 @@ private void EnqueueChunk(T[] chunk) // write; the CLR 2.0 memory model ensures the write won't move before the write to the // corresponding element, so a consumer won't see the new index but the corresponding // element in the array as empty. -#pragma warning disable 0420 Interlocked.Exchange(ref _producerBufferIndex, (bufferIndex + 1) % _buffer.Length); -#pragma warning restore 0420 // (If there is a consumer waiting, we have to ensure to signal the event. Unfortunately, // this requires that we issue a memory barrier: We need to guarantee that the write to @@ -338,9 +336,7 @@ private void WaitUntilNonFull() // very quickly, suddenly seeing an empty queue. This would lead to deadlock // if we aren't careful. Therefore we check the empty/full state AGAIN after // setting our flag to see if a real wait is warranted. -#pragma warning disable 0420 Interlocked.Exchange(ref _producerIsWaiting, 1); -#pragma warning restore 0420 // (We have to prevent the reads that go into determining whether the buffer // is full from moving before the write to the producer-wait flag. Hence the CAS.) @@ -557,9 +553,7 @@ private bool TryDequeueChunk(ref T[] chunk, ref bool isDone) // very quickly, suddenly seeing a full queue. This would lead to deadlock // if we aren't careful. Therefore we check the empty/full state AGAIN after // setting our flag to see if a real wait is warranted. -#pragma warning disable 0420 Interlocked.Exchange(ref _consumerIsWaiting, 1); -#pragma warning restore 0420 // (We have to prevent the reads that go into determining whether the buffer // is full from moving before the write to the producer-wait flag. Hence the CAS.) @@ -619,9 +613,7 @@ private T[] InternalDequeueChunk() // write; the CLR 2.0 memory model ensures the write won't move before the write to the // corresponding element, so a consumer won't see the new index but the corresponding // element in the array as empty. -#pragma warning disable 0420 Interlocked.Exchange(ref _consumerBufferIndex, (consumerBufferIndex + 1) % _buffer.Length); -#pragma warning restore 0420 // (Unfortunately, this whole sequence requires a memory barrier: We need to guarantee // that the write to _consumerBufferIndex doesn't pass the read of the wait-flags; the CLR memory diff --git a/src/libraries/System.Runtime.Caching/src/System/Runtime/Caching/SafeBitVector32.cs b/src/libraries/System.Runtime.Caching/src/System/Runtime/Caching/SafeBitVector32.cs index 6c876c4ae2176..ec4c8ed0a3505 100644 --- a/src/libraries/System.Runtime.Caching/src/System/Runtime/Caching/SafeBitVector32.cs +++ b/src/libraries/System.Runtime.Caching/src/System/Runtime/Caching/SafeBitVector32.cs @@ -37,10 +37,7 @@ internal bool this[int bit] newData = oldData & ~bit; } -#pragma warning disable 0420 int result = Interlocked.CompareExchange(ref _data, newData, oldData); -#pragma warning restore 0420 - if (result == oldData) { break; @@ -69,10 +66,7 @@ internal bool ChangeValue(int bit, bool value) return false; } -#pragma warning disable 0420 int result = Interlocked.CompareExchange(ref _data, newData, oldData); -#pragma warning restore 0420 - if (result == oldData) { return true; diff --git a/src/libraries/System.Runtime.WindowsRuntime/src/System/IO/StreamOperationAsyncResult.cs b/src/libraries/System.Runtime.WindowsRuntime/src/System/IO/StreamOperationAsyncResult.cs index 6ecb51198d29f..b903ec0409b49 100644 --- a/src/libraries/System.Runtime.WindowsRuntime/src/System/IO/StreamOperationAsyncResult.cs +++ b/src/libraries/System.Runtime.WindowsRuntime/src/System/IO/StreamOperationAsyncResult.cs @@ -69,8 +69,6 @@ internal bool ProcessCompletedOperationInCallback } -#pragma warning disable 420 // "a reference to a volatile field will not be treated as volatile" - public WaitHandle AsyncWaitHandle { get @@ -97,9 +95,6 @@ public WaitHandle AsyncWaitHandle } } -#pragma warning restore 420 // "a reference to a volatile field will not be treated as volatile" - - public bool CompletedSynchronously { get { return false; } diff --git a/src/libraries/System.Runtime.WindowsRuntime/src/System/Threading/Tasks/TaskToAsyncInfoAdapter.cs b/src/libraries/System.Runtime.WindowsRuntime/src/System/Threading/Tasks/TaskToAsyncInfoAdapter.cs index 7d3202eac7a71..48677d58e0cef 100644 --- a/src/libraries/System.Runtime.WindowsRuntime/src/System/Threading/Tasks/TaskToAsyncInfoAdapter.cs +++ b/src/libraries/System.Runtime.WindowsRuntime/src/System/Threading/Tasks/TaskToAsyncInfoAdapter.cs @@ -21,10 +21,6 @@ internal class TaskToAsyncInfoAdapter } // namespace diff --git a/src/libraries/System.Threading.Tasks.Dataflow/src/Internal/ConcurrentQueue.cs b/src/libraries/System.Threading.Tasks.Dataflow/src/Internal/ConcurrentQueue.cs index 8db9d7ab2670c..ce4f5971708ff 100644 --- a/src/libraries/System.Threading.Tasks.Dataflow/src/Internal/ConcurrentQueue.cs +++ b/src/libraries/System.Threading.Tasks.Dataflow/src/Internal/ConcurrentQueue.cs @@ -1,8 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#pragma warning disable 0420 - // =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ // diff --git a/src/libraries/System.Threading.Tasks.Dataflow/src/Internal/SourceCore.cs b/src/libraries/System.Threading.Tasks.Dataflow/src/Internal/SourceCore.cs index 8c1a0a65fb1c7..ab7e23be6e464 100644 --- a/src/libraries/System.Threading.Tasks.Dataflow/src/Internal/SourceCore.cs +++ b/src/libraries/System.Threading.Tasks.Dataflow/src/Internal/SourceCore.cs @@ -769,9 +769,7 @@ private void OfferAsyncIfNecessary_Slow(bool isReplacementReplica, bool outgoing #endif // Start the task handling scheduling exceptions -#pragma warning disable 0420 Exception exception = Common.StartTaskSafe(_taskForOutputProcessing, _dataflowBlockOptions.TaskScheduler); -#pragma warning restore 0420 if (exception != null) { // First, log the exception while the processing state is dirty which is preventing the block from completing. diff --git a/src/libraries/System.Threading.Tasks.Dataflow/src/Internal/SpscTargetCore.cs b/src/libraries/System.Threading.Tasks.Dataflow/src/Internal/SpscTargetCore.cs index 127901531f0c8..66c55d16c1e1a 100644 --- a/src/libraries/System.Threading.Tasks.Dataflow/src/Internal/SpscTargetCore.cs +++ b/src/libraries/System.Threading.Tasks.Dataflow/src/Internal/SpscTargetCore.cs @@ -18,7 +18,6 @@ using System.Runtime.CompilerServices; using System.Security; -#pragma warning disable 0420 // turn off warning for passing volatiles to interlocked operations namespace System.Threading.Tasks.Dataflow.Internal { // SpscTargetCore provides a fast target core for use in blocks that will only have single-producer-single-consumer @@ -313,7 +312,9 @@ private void StoreException(Exception exception) // the exception because this method could be accessed concurrently // by the producer and consumer, a producer calling Fault and the // processing task processing the user delegate which might throw. +#pragma warning disable 0420 lock (LazyInitializer.EnsureInitialized(ref _exceptions, () => new List())) +#pragma warning restore 0420 { _exceptions.Add(exception); } diff --git a/src/libraries/System.Threading.Tasks.Dataflow/src/Internal/TargetCore.cs b/src/libraries/System.Threading.Tasks.Dataflow/src/Internal/TargetCore.cs index 98660356989f6..049b6d22cd635 100644 --- a/src/libraries/System.Threading.Tasks.Dataflow/src/Internal/TargetCore.cs +++ b/src/libraries/System.Threading.Tasks.Dataflow/src/Internal/TargetCore.cs @@ -155,8 +155,6 @@ internal void Complete(Exception exception, bool dropPendingMessages, bool store { Debug.Assert(_numberOfOutstandingOperations > 0 || !storeExceptionEvenIfAlreadyCompleting, "Calls with storeExceptionEvenIfAlreadyCompleting==true may only be coming from processing task."); - -#pragma warning disable 0420 Common.AddException(ref _exceptions, exception, unwrapInnerExceptions); } diff --git a/src/libraries/System.Threading.Tasks.Parallel/src/System/Threading/Tasks/ParallelLoopState.cs b/src/libraries/System.Threading.Tasks.Parallel/src/System/Threading/Tasks/ParallelLoopState.cs index e3005a0bbbb39..1b1921c78e444 100644 --- a/src/libraries/System.Threading.Tasks.Parallel/src/System/Threading/Tasks/ParallelLoopState.cs +++ b/src/libraries/System.Threading.Tasks.Parallel/src/System/Threading/Tasks/ParallelLoopState.cs @@ -13,7 +13,6 @@ // Prevents compiler warnings/errors regarding the use of ref params in Interlocked methods -#pragma warning disable 0420 namespace System.Threading.Tasks { /// @@ -624,5 +623,3 @@ public struct ParallelLoopResult public long? LowestBreakIteration { get { return _lowestBreakIteration; } } } } - -#pragma warning restore 0420 diff --git a/src/libraries/System.Threading.Tasks.Parallel/src/System/Threading/Tasks/ParallelRangeManager.cs b/src/libraries/System.Threading.Tasks.Parallel/src/System/Threading/Tasks/ParallelRangeManager.cs index 258ff5d095d13..7832b5d16e976 100644 --- a/src/libraries/System.Threading.Tasks.Parallel/src/System/Threading/Tasks/ParallelRangeManager.cs +++ b/src/libraries/System.Threading.Tasks.Parallel/src/System/Threading/Tasks/ParallelRangeManager.cs @@ -11,7 +11,6 @@ using System.Diagnostics; using System.Runtime.InteropServices; -#pragma warning disable 0420 namespace System.Threading.Tasks { /// @@ -299,4 +298,3 @@ internal RangeWorker RegisterNewWorker() } } } -#pragma warning restore 0420 diff --git a/src/libraries/System.Threading/src/System/Threading/Barrier.cs b/src/libraries/System.Threading/src/System/Threading/Barrier.cs index 0463a338b4e4c..69b2a5f861ee6 100644 --- a/src/libraries/System.Threading/src/System/Threading/Barrier.cs +++ b/src/libraries/System.Threading/src/System/Threading/Barrier.cs @@ -267,9 +267,7 @@ private bool SetCurrentTotal(int currentTotal, int current, int total, bool sens newCurrentTotal |= SENSE_MASK; } -#pragma warning disable 0420 return Interlocked.CompareExchange(ref _currentTotalCount, newCurrentTotal, currentTotal) == currentTotal; -#pragma warning restore 0420 } /// diff --git a/src/libraries/System.Threading/src/System/Threading/CountdownEvent.cs b/src/libraries/System.Threading/src/System/Threading/CountdownEvent.cs index 989e0519f30a7..75eac661d339b 100644 --- a/src/libraries/System.Threading/src/System/Threading/CountdownEvent.cs +++ b/src/libraries/System.Threading/src/System/Threading/CountdownEvent.cs @@ -182,9 +182,8 @@ public bool Signal() { throw new InvalidOperationException(SR.CountdownEvent_Decrement_BelowZero); } -#pragma warning disable 0420 + int newCount = Interlocked.Decrement(ref _currentCount); -#pragma warning restore 0420 if (newCount == 0) { _event.Set(); @@ -237,11 +236,7 @@ public bool Signal(int signalCount) throw new InvalidOperationException(SR.CountdownEvent_Decrement_BelowZero); } - // This disables the "CS0420: a reference to a volatile field will not be treated as volatile" warning - // for this statement. This warning is clearly senseless for Interlocked operations. -#pragma warning disable 0420 if (Interlocked.CompareExchange(ref _currentCount, observedCount - signalCount, observedCount) == observedCount) -#pragma warning restore 0420 { break; } @@ -351,11 +346,7 @@ public bool TryAddCount(int signalCount) throw new InvalidOperationException(SR.CountdownEvent_Increment_AlreadyMax); } - // This disables the "CS0420: a reference to a volatile field will not be treated as volatile" warning - // for this statement. This warning is clearly senseless for Interlocked operations. -#pragma warning disable 0420 if (Interlocked.CompareExchange(ref _currentCount, observedCount + signalCount, observedCount) == observedCount) -#pragma warning restore 0420 { break; }