Merge pull request #19629 from jtattermusch/csharp_sync_completion_queue_atomic

dont use shutdownRef count for sync completion queue
pull/19634/head
Jan Tattermusch 6 years ago committed by GitHub
commit 970ae3c112
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      src/csharp/Grpc.Core/Internal/CompletionQueueSafeHandle.cs

@ -29,7 +29,7 @@ namespace Grpc.Core.Internal
{
static readonly NativeMethods Native = NativeMethods.Get();
AtomicCounter shutdownRefcount = new AtomicCounter(1);
AtomicCounter shutdownRefcount;
CompletionRegistry completionRegistry;
private CompletionQueueSafeHandle()
@ -51,6 +51,7 @@ namespace Grpc.Core.Internal
{
var cq = Native.grpcsharp_completion_queue_create_async();
cq.completionRegistry = completionRegistry;
cq.shutdownRefcount = new AtomicCounter(1);
return cq;
}
@ -95,7 +96,7 @@ namespace Grpc.Core.Internal
private void DecrementShutdownRefcount()
{
if (shutdownRefcount.Decrement() == 0)
if (shutdownRefcount == null || shutdownRefcount.Decrement() == 0)
{
Native.grpcsharp_completion_queue_shutdown(this);
}
@ -103,6 +104,7 @@ namespace Grpc.Core.Internal
private void BeginOp()
{
GrpcPreconditions.CheckNotNull(shutdownRefcount, nameof(shutdownRefcount));
bool success = false;
shutdownRefcount.IncrementIfNonzero(ref success);
GrpcPreconditions.CheckState(success, "Shutdown has already been called");
@ -110,6 +112,7 @@ namespace Grpc.Core.Internal
private void EndOp()
{
GrpcPreconditions.CheckNotNull(shutdownRefcount, nameof(shutdownRefcount));
DecrementShutdownRefcount();
}

Loading…
Cancel
Save