PendingQuestion: removed unnecessary finalizer

This commit is contained in:
Christian Köllner 2020-04-04 23:10:54 +02:00
parent ac50b7454a
commit 01513ef71f

View File

@ -49,13 +49,7 @@ namespace Capnp.Rpc
/// <summary> /// <summary>
/// Question object was disposed. /// Question object was disposed.
/// </summary> /// </summary>
Disposed = 16, Disposed = 16
/// <summary>
/// Question object was finalized by GC.
/// This flag should only be observable when debugging the finalizer itself.
/// </summary>
Finalized = 32
} }
readonly TaskCompletionSource<DeserializerState> _tcs = new TaskCompletionSource<DeserializerState>(); readonly TaskCompletionSource<DeserializerState> _tcs = new TaskCompletionSource<DeserializerState>();
@ -76,7 +70,7 @@ namespace Capnp.Rpc
{ {
foreach (var cap in inParams.Caps!) foreach (var cap in inParams.Caps!)
{ {
cap?.AddRef(); cap.AddRef();
} }
} }
@ -279,7 +273,7 @@ namespace Capnp.Rpc
{ {
foreach (var cap in inParams.Caps!) foreach (var cap in inParams.Caps!)
{ {
cap?.Release(); cap.Release();
} }
} }
@ -293,7 +287,7 @@ namespace Capnp.Rpc
{ {
foreach (var cap in outParams.Caps!) foreach (var cap in outParams.Caps!)
{ {
cap?.Release(); cap.Release();
} }
} }
@ -332,25 +326,17 @@ namespace Capnp.Rpc
OnException(exception); OnException(exception);
} }
ReleaseCaps(target!, inParams); ReleaseCaps(target, inParams);
} }
#region IDisposable Support /// <summary>
/// Implements <see cref="IDisposable"/>.
void Dispose(bool disposing) /// </summary>
public void Dispose()
{ {
SerializerState? inParams;
ConsumedCapability? target;
bool justDisposed = false; bool justDisposed = false;
lock (ReentrancyBlocker) lock (ReentrancyBlocker)
{
inParams = _inParams;
_inParams = null;
target = _target;
_target = null;
if (disposing)
{ {
if (!StateFlags.HasFlag(State.Disposed)) if (!StateFlags.HasFlag(State.Disposed))
{ {
@ -360,36 +346,11 @@ namespace Capnp.Rpc
AutoFinish(); AutoFinish();
} }
} }
else
{
StateFlags |= State.Finalized;
}
}
ReleaseCaps(target, inParams);
if (justDisposed) if (justDisposed)
{ {
_tcs.TrySetCanceled(); _tcs.TrySetCanceled();
} }
} }
/// <summary>
/// Finalizer
/// </summary>
~PendingQuestion()
{
Dispose(false);
}
/// <summary>
/// Implements <see cref="IDisposable"/>.
/// </summary>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
#endregion
} }
} }