Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of Interlocked on volatile fields no longer raises CS0420 #345

Merged
merged 1 commit into from
Apr 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ public bool IsDisposed
/// </summary>
public void Dispose()
{
#pragma warning disable 0420
var dispose = Interlocked.Exchange(ref _dispose, null);
#pragma warning restore 0420
if (dispose != null)
{
dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ public bool IsDisposed
/// </summary>
public void Dispose()
{
#pragma warning disable 0420
var disposable = Interlocked.Exchange(ref _disposable, BooleanDisposable.True);
#pragma warning restore 0420

if (disposable != BooleanDisposable.True)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ public void Dispose()

private void DisposeInner()
{
#pragma warning disable 0420
var disposable = Interlocked.Exchange(ref _disposable, BooleanDisposable.True);
#pragma warning restore 0420

if (disposable != BooleanDisposable.True)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ public IDisposable Disposable

set
{
#pragma warning disable 0420
var old = Interlocked.CompareExchange(ref _current, value, null);
#pragma warning restore 0420
if (old == null)
return;

Expand All @@ -72,9 +70,7 @@ public IDisposable Disposable
/// </summary>
public void Dispose()
{
#pragma warning disable 0420
var old = Interlocked.Exchange(ref _current, BooleanDisposable.True);
#pragma warning restore 0420
if (old != null)
old.Dispose();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,13 @@ public override bool IsDisposed

public override void Dispose()
{
#pragma warning disable 0420
var old1 = Interlocked.Exchange(ref _disposable1, null);
#pragma warning restore 0420
if (old1 != null)
{
old1.Dispose();
}

#pragma warning disable 0420
var old2 = Interlocked.Exchange(ref _disposable2, null);
#pragma warning restore 0420
if (old2 != null)
{
old2.Dispose();
Expand Down Expand Up @@ -136,9 +132,7 @@ public override bool IsDisposed

public override void Dispose()
{
#pragma warning disable 0420
var old = Interlocked.Exchange(ref _disposables, null);
#pragma warning restore 0420
if (old != null)
{
foreach (var d in old)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ private void EnsureActiveSlow()
{
var isOwner = false;

#pragma warning disable 0420
while (true)
{
var old = Interlocked.CompareExchange(ref _state, RUNNING, STOPPED);
Expand Down Expand Up @@ -177,7 +176,6 @@ private void EnsureActiveSlow()
if (old == PENDING || old == RUNNING && Interlocked.CompareExchange(ref _state, PENDING, RUNNING) == RUNNING)
break;
}
#pragma warning restore 0420

if (isOwner)
{
Expand All @@ -187,7 +185,6 @@ private void EnsureActiveSlow()

private void Run(object state, Action<object> recurse)
{
#pragma warning disable 0420
var next = default(T);
while (!_queue.TryDequeue(out next))
{
Expand Down Expand Up @@ -254,17 +251,13 @@ private void Run(object state, Action<object> recurse)

Interlocked.Exchange(ref _state, RUNNING);

#pragma warning restore 0420

try
{
_observer.OnNext(next);
}
catch
{
#pragma warning disable 0420
Interlocked.Exchange(ref _state, FAULTED);
#pragma warning restore 0420

var nop = default(T);
while (_queue.TryDequeue(out nop))
Expand Down
2 changes: 0 additions & 2 deletions Rx.NET/Source/src/System.Reactive/Linq/Observable/Merge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,6 @@ public void OnCompleted()
}

#if !NO_TPL
#pragma warning disable 0420
class MergeImpl : Sink<TSource>, IObserver<Task<TSource>>
{
private readonly Merge<TSource> _parent;
Expand Down Expand Up @@ -398,7 +397,6 @@ public void OnCompleted()
}
}
}
#pragma warning restore 0420
#endif
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,6 @@ public void OnCompleted()
}

#if !NO_TPL
#pragma warning disable 0420
class SelectManyImpl : Sink<TResult>, IObserver<TSource>
{
private readonly SelectMany<TSource, TCollection, TResult> _parent;
Expand Down Expand Up @@ -858,7 +857,6 @@ public void OnCompleted()
}
}
}
#pragma warning restore 0420
#endif
}

Expand Down Expand Up @@ -1513,7 +1511,6 @@ public void OnCompleted()
}

#if !NO_TPL
#pragma warning disable 0420
class SelectManyImpl : Sink<TResult>, IObserver<TSource>
{
private readonly SelectMany<TSource, TResult> _parent;
Expand Down Expand Up @@ -1734,7 +1731,6 @@ public void OnCompleted()
}
}
}
#pragma warning restore 0420
#endif
}
}
Expand Down
2 changes: 0 additions & 2 deletions Rx.NET/Source/src/System.Reactive/Subjects/ReplaySubject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -982,9 +982,7 @@ public void OnNext(T value)
/// <returns>Observer to send terminal notifications to.</returns>
private IObserver<T> Done()
{
#pragma warning disable 0420
return Interlocked.Exchange(ref _observer, NopObserver<T>.Instance);
#pragma warning restore 0420
}
}
}
8 changes: 0 additions & 8 deletions Rx.NET/Source/src/System.Reactive/Subjects/Subject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ public override void OnCompleted()

if (oldObserver == DisposedObserver<T>.Instance || oldObserver is DoneObserver<T>)
break;
#pragma warning disable 0420
} while (Interlocked.CompareExchange(ref _observer, newObserver, oldObserver) != oldObserver);
#pragma warning restore 0420

oldObserver.OnCompleted();
}
Expand All @@ -103,9 +101,7 @@ public override void OnError(Exception error)

if (oldObserver == DisposedObserver<T>.Instance || oldObserver is DoneObserver<T>)
break;
#pragma warning disable 0420
} while (Interlocked.CompareExchange(ref _observer, newObserver, oldObserver) != oldObserver);
#pragma warning restore 0420

oldObserver.OnError(error);
}
Expand Down Expand Up @@ -175,9 +171,7 @@ public override IDisposable Subscribe(IObserver<T> observer)
newObserver = new Observer<T>(new ImmutableList<IObserver<T>>(new[] { oldObserver, observer }));
}
}
#pragma warning disable 0420
} while (Interlocked.CompareExchange(ref _observer, newObserver, oldObserver) != oldObserver);
#pragma warning restore 0420

return new Subscription(this, observer);
}
Expand Down Expand Up @@ -228,9 +222,7 @@ private void Unsubscribe(IObserver<T> observer)

newObserver = NopObserver<T>.Instance;
}
#pragma warning disable 0420
} while (Interlocked.CompareExchange(ref _observer, newObserver, oldObserver) != oldObserver);
#pragma warning restore 0420
}

#endregion
Expand Down