dont use shutdownRef count for sync completion queue
diff --git a/src/csharp/Grpc.Core/Internal/CompletionQueueSafeHandle.cs b/src/csharp/Grpc.Core/Internal/CompletionQueueSafeHandle.cs
index 28135d7..25540b4 100644
--- a/src/csharp/Grpc.Core/Internal/CompletionQueueSafeHandle.cs
+++ b/src/csharp/Grpc.Core/Internal/CompletionQueueSafeHandle.cs
@@ -29,7 +29,7 @@
{
static readonly NativeMethods Native = NativeMethods.Get();
- AtomicCounter shutdownRefcount = new AtomicCounter(1);
+ AtomicCounter shutdownRefcount;
CompletionRegistry completionRegistry;
private CompletionQueueSafeHandle()
@@ -51,6 +51,7 @@
{
var cq = Native.grpcsharp_completion_queue_create_async();
cq.completionRegistry = completionRegistry;
+ cq.shutdownRefcount = new AtomicCounter(1);
return cq;
}
@@ -95,7 +96,7 @@
private void DecrementShutdownRefcount()
{
- if (shutdownRefcount.Decrement() == 0)
+ if (shutdownRefcount == null || shutdownRefcount.Decrement() == 0)
{
Native.grpcsharp_completion_queue_shutdown(this);
}
@@ -103,14 +104,20 @@
private void BeginOp()
{
- bool success = false;
- shutdownRefcount.IncrementIfNonzero(ref success);
- GrpcPreconditions.CheckState(success, "Shutdown has already been called");
+ if (shutdownRefcount != null)
+ {
+ bool success = false;
+ shutdownRefcount.IncrementIfNonzero(ref success);
+ GrpcPreconditions.CheckState(success, "Shutdown has already been called");
+ }
}
private void EndOp()
{
- DecrementShutdownRefcount();
+ if (shutdownRefcount != null)
+ {
+ DecrementShutdownRefcount();
+ }
}
// Allows declaring BeginOp and EndOp of a completion queue with a using statement.