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;
{
// 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;
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();
ToList().CopyTo(array, index);
}
-#pragma warning disable 0420 // No warning for Interlocked.xxx if compiled with new managed compiler (Roslyn)
/// <summary>
/// Inserts an object at the top of the <see cref="ConcurrentStack{T}"/>.
/// </summary>
}
}
}
-#pragma warning restore 0420
/// <summary>
/// Local helper function to copy the popped elements into a given collection
return ((InternalPartitionEnumerable)this).GetEnumerator();
}
-#pragma warning disable 0420 // No warning for Interlocked.xxx if compiled with new managed compiler (Roslyn)
///////////////////
//
// Used by GrabChunk_Buffered()
{
_localList = new KeyValuePair<long, TSource>[_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
}
/// <summary>
}
}
#endregion
-#pragma warning restore 0420
}
#endregion
{
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();
}
{
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)
{
{
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)
{
// 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);
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;
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);
}
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
+}
}
}
-#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);
}
}
-#pragma warning restore 0420
-
/////////////////////////////////////////
// Network/Packet Writing & Processing //
/////////////////////////////////////////
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)
{
}
// 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)))
}
}
-#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
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)
{
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
{
/// <summary>
// 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
// 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.)
// 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.)
// 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
newData = oldData & ~bit;
}
-#pragma warning disable 0420
int result = Interlocked.CompareExchange(ref _data, newData, oldData);
-#pragma warning restore 0420
-
if (result == oldData)
{
break;
return false;
}
-#pragma warning disable 0420
int result = Interlocked.CompareExchange(ref _data, newData, oldData);
-#pragma warning restore 0420
-
if (result == oldData)
{
return true;
}
-#pragma warning disable 420 // "a reference to a volatile field will not be treated as volatile"
-
public WaitHandle AsyncWaitHandle
{
get
}
}
-#pragma warning restore 420 // "a reference to a volatile field will not be treated as volatile"
-
-
public bool CompletedSynchronously
{
get { return false; }
where TCompletedHandler : class
where TProgressHandler : class
{
- // This class uses interlocked operations on volatile fields, and this pragma suppresses the compiler's complaint
- // that passing a volatile by ref to a function removes the volatility. That's not necessary for interlocked.
-#pragma warning disable 0420
-
#region Private Types, Statics and Constants
// ! THIS DIAGRAM ILLUSTRATES THE CONSTANTS BELOW. UPDATE THIS IF UPDATING THE CONSTANTS BELOW!:
}
}
#endregion Implementation of IAsyncInfo
-
-#pragma warning restore 0420
-
} // class TaskToAsyncInfoAdapter<TCompletedHandler, TProgressHandler, TResult, TProgressInfo>
} // namespace
// 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
-
// =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
//
#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.
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
// 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<Exception>()))
+#pragma warning restore 0420
{
_exceptions.Add(exception);
}
{
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);
}
// Prevents compiler warnings/errors regarding the use of ref params in Interlocked methods
-#pragma warning disable 0420
namespace System.Threading.Tasks
{
/// <summary>
public long? LowestBreakIteration { get { return _lowestBreakIteration; } }
}
}
-
-#pragma warning restore 0420
using System.Diagnostics;
using System.Runtime.InteropServices;
-#pragma warning disable 0420
namespace System.Threading.Tasks
{
/// <summary>
}
}
}
-#pragma warning restore 0420
newCurrentTotal |= SENSE_MASK;
}
-#pragma warning disable 0420
return Interlocked.CompareExchange(ref _currentTotalCount, newCurrentTotal, currentTotal) == currentTotal;
-#pragma warning restore 0420
}
/// <summary>
{
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();
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;
}
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;
}