@ -34,6 +34,7 @@
# include <list>
# include <list>
# include <grpc/grpc.h>
# include <grpc/support/atm.h>
# include <grpc/support/atm.h>
# include <grpcpp/impl/codegen/core_codegen_interface.h>
# include <grpcpp/impl/codegen/core_codegen_interface.h>
# include <grpcpp/impl/codegen/rpc_service_method.h>
# include <grpcpp/impl/codegen/rpc_service_method.h>
@ -115,9 +116,7 @@ class CompletionQueue : private grpc::internal::GrpcLibrary {
explicit CompletionQueue ( grpc_completion_queue * take ) ;
explicit CompletionQueue ( grpc_completion_queue * take ) ;
/// Destructor. Destroys the owned wrapped completion queue / instance.
/// Destructor. Destroys the owned wrapped completion queue / instance.
~ CompletionQueue ( ) override {
~ CompletionQueue ( ) override { grpc_completion_queue_destroy ( cq_ ) ; }
grpc : : g_core_codegen_interface - > grpc_completion_queue_destroy ( cq_ ) ;
}
/// Tri-state return for AsyncNext: SHUTDOWN, GOT_EVENT, TIMEOUT.
/// Tri-state return for AsyncNext: SHUTDOWN, GOT_EVENT, TIMEOUT.
enum NextStatus {
enum NextStatus {
@ -250,10 +249,9 @@ class CompletionQueue : private grpc::internal::GrpcLibrary {
protected :
protected :
/// Private constructor of CompletionQueue only visible to friend classes
/// Private constructor of CompletionQueue only visible to friend classes
explicit CompletionQueue ( const grpc_completion_queue_attributes & attributes ) {
explicit CompletionQueue ( const grpc_completion_queue_attributes & attributes ) {
cq_ = grpc : : g_core_codegen_interface - > grpc_completion_queue_create (
cq_ = grpc_completion_queue_create (
grpc : : g_core_codegen_interface - > grpc_completion_queue_factory_lookup (
grpc_completion_queue_factory_lookup ( & attributes ) , & attributes ,
& attributes ) ,
nullptr ) ;
& attributes , nullptr ) ;
InitialAvalanching ( ) ; // reserve this for the future shutdown
InitialAvalanching ( ) ; // reserve this for the future shutdown
}
}
@ -324,8 +322,7 @@ class CompletionQueue : private grpc::internal::GrpcLibrary {
auto deadline =
auto deadline =
grpc : : g_core_codegen_interface - > gpr_inf_future ( GPR_CLOCK_REALTIME ) ;
grpc : : g_core_codegen_interface - > gpr_inf_future ( GPR_CLOCK_REALTIME ) ;
while ( true ) {
while ( true ) {
auto ev = grpc : : g_core_codegen_interface - > grpc_completion_queue_pluck (
auto ev = grpc_completion_queue_pluck ( cq_ , tag , deadline , nullptr ) ;
cq_ , tag , deadline , nullptr ) ;
bool ok = ev . success ! = 0 ;
bool ok = ev . success ! = 0 ;
void * ignored = tag ;
void * ignored = tag ;
if ( tag - > FinalizeResult ( & ignored , & ok ) ) {
if ( tag - > FinalizeResult ( & ignored , & ok ) ) {
@ -346,8 +343,7 @@ class CompletionQueue : private grpc::internal::GrpcLibrary {
void TryPluck ( grpc : : internal : : CompletionQueueTag * tag ) {
void TryPluck ( grpc : : internal : : CompletionQueueTag * tag ) {
auto deadline =
auto deadline =
grpc : : g_core_codegen_interface - > gpr_time_0 ( GPR_CLOCK_REALTIME ) ;
grpc : : g_core_codegen_interface - > gpr_time_0 ( GPR_CLOCK_REALTIME ) ;
auto ev = grpc : : g_core_codegen_interface - > grpc_completion_queue_pluck (
auto ev = grpc_completion_queue_pluck ( cq_ , tag , deadline , nullptr ) ;
cq_ , tag , deadline , nullptr ) ;
if ( ev . type = = GRPC_QUEUE_TIMEOUT ) return ;
if ( ev . type = = GRPC_QUEUE_TIMEOUT ) return ;
bool ok = ev . success ! = 0 ;
bool ok = ev . success ! = 0 ;
void * ignored = tag ;
void * ignored = tag ;
@ -362,8 +358,7 @@ class CompletionQueue : private grpc::internal::GrpcLibrary {
/// that the tag is internal not something that is returned to the user.
/// that the tag is internal not something that is returned to the user.
void TryPluck ( grpc : : internal : : CompletionQueueTag * tag ,
void TryPluck ( grpc : : internal : : CompletionQueueTag * tag ,
gpr_timespec deadline ) {
gpr_timespec deadline ) {
auto ev = grpc : : g_core_codegen_interface - > grpc_completion_queue_pluck (
auto ev = grpc_completion_queue_pluck ( cq_ , tag , deadline , nullptr ) ;
cq_ , tag , deadline , nullptr ) ;
if ( ev . type = = GRPC_QUEUE_TIMEOUT | | ev . type = = GRPC_QUEUE_SHUTDOWN ) {
if ( ev . type = = GRPC_QUEUE_TIMEOUT | | ev . type = = GRPC_QUEUE_SHUTDOWN ) {
return ;
return ;
}
}
@ -388,7 +383,7 @@ class CompletionQueue : private grpc::internal::GrpcLibrary {
void CompleteAvalanching ( ) {
void CompleteAvalanching ( ) {
if ( gpr_atm_no_barrier_fetch_add ( & avalanches_in_flight_ , gpr_atm { - 1 } ) = =
if ( gpr_atm_no_barrier_fetch_add ( & avalanches_in_flight_ , gpr_atm { - 1 } ) = =
1 ) {
1 ) {
grpc : : g_core_codegen_interface - > grpc _completion_queue_shutdown( cq_ ) ;
grpc_completion_queue_shutdown ( cq_ ) ;
}
}
}
}