diff --git a/Capnp.Net.Runtime/Rpc/PendingQuestion.cs b/Capnp.Net.Runtime/Rpc/PendingQuestion.cs index 394f4f2..2009b14 100644 --- a/Capnp.Net.Runtime/Rpc/PendingQuestion.cs +++ b/Capnp.Net.Runtime/Rpc/PendingQuestion.cs @@ -49,13 +49,7 @@ namespace Capnp.Rpc /// /// Question object was disposed. /// - Disposed = 16, - - /// - /// Question object was finalized by GC. - /// This flag should only be observable when debugging the finalizer itself. - /// - Finalized = 32 + Disposed = 16 } readonly TaskCompletionSource _tcs = new TaskCompletionSource(); @@ -76,7 +70,7 @@ namespace Capnp.Rpc { foreach (var cap in inParams.Caps!) { - cap?.AddRef(); + cap.AddRef(); } } @@ -279,7 +273,7 @@ namespace Capnp.Rpc { foreach (var cap in inParams.Caps!) { - cap?.Release(); + cap.Release(); } } @@ -293,7 +287,7 @@ namespace Capnp.Rpc { foreach (var cap in outParams.Caps!) { - cap?.Release(); + cap.Release(); } } @@ -332,54 +326,7 @@ namespace Capnp.Rpc OnException(exception); } - ReleaseCaps(target!, inParams); - } - - #region IDisposable Support - - void Dispose(bool disposing) - { - SerializerState? inParams; - ConsumedCapability? target; - bool justDisposed = false; - - lock (ReentrancyBlocker) - { - inParams = _inParams; - _inParams = null; - target = _target; - _target = null; - - if (disposing) - { - if (!StateFlags.HasFlag(State.Disposed)) - { - StateFlags |= State.Disposed; - justDisposed = true; - - AutoFinish(); - } - } - else - { - StateFlags |= State.Finalized; - } - } - ReleaseCaps(target, inParams); - - if (justDisposed) - { - _tcs.TrySetCanceled(); - } - } - - /// - /// Finalizer - /// - ~PendingQuestion() - { - Dispose(false); } /// @@ -387,9 +334,23 @@ namespace Capnp.Rpc /// public void Dispose() { - Dispose(true); - GC.SuppressFinalize(this); + bool justDisposed = false; + + lock (ReentrancyBlocker) + { + if (!StateFlags.HasFlag(State.Disposed)) + { + StateFlags |= State.Disposed; + justDisposed = true; + + AutoFinish(); + } + } + + if (justDisposed) + { + _tcs.TrySetCanceled(); + } } - #endregion } } \ No newline at end of file