diff options
Diffstat (limited to 'include/grpc++/impl')
-rw-r--r-- | include/grpc++/impl/codegen/grpc_library.h | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/include/grpc++/impl/codegen/grpc_library.h b/include/grpc++/impl/codegen/grpc_library.h index 2b11aff214..3735d04e8c 100644 --- a/include/grpc++/impl/codegen/grpc_library.h +++ b/include/grpc++/impl/codegen/grpc_library.h @@ -51,18 +51,26 @@ extern GrpcLibraryInterface* g_glip; /// Classes that require gRPC to be initialized should inherit from this class. class GrpcLibraryCodegen { public: - GrpcLibraryCodegen() { - GPR_CODEGEN_ASSERT(g_glip && - "gRPC library not initialized. See " - "grpc::internal::GrpcLibraryInitializer."); - g_glip->init(); + GrpcLibraryCodegen(bool call_grpc_init = true) : grpc_init_called_(false) { + if (call_grpc_init) { + GPR_CODEGEN_ASSERT(g_glip && + "gRPC library not initialized. See " + "grpc::internal::GrpcLibraryInitializer."); + g_glip->init(); + grpc_init_called_ = true; + } } virtual ~GrpcLibraryCodegen() { - GPR_CODEGEN_ASSERT(g_glip && - "gRPC library not initialized. See " - "grpc::internal::GrpcLibraryInitializer."); - g_glip->shutdown(); + if (grpc_init_called_) { + GPR_CODEGEN_ASSERT(g_glip && + "gRPC library not initialized. See " + "grpc::internal::GrpcLibraryInitializer."); + g_glip->shutdown(); + } } + + private: + bool grpc_init_called_; }; } // namespace grpc |