add init checks
This commit is contained in:
parent
9d48ebfdc3
commit
269676209e
|
|
@ -51,7 +51,9 @@ enum census_functions {
|
|||
|
||||
/* Shutdown and startup census subsystem. The 'functions' argument should be
|
||||
* the OR (|) of census_functions values. If census fails to initialize, then
|
||||
* census_initialize() will return a non-zero value. */
|
||||
* census_initialize() will return a non-zero value. It is an error to call
|
||||
* census_initialize() more than once (without an intervening
|
||||
* census_shutdown()). */
|
||||
int census_initialize(int functions);
|
||||
void census_shutdown();
|
||||
|
||||
|
|
|
|||
|
|
@ -33,6 +33,18 @@
|
|||
|
||||
#include <grpc/census.h>
|
||||
|
||||
int census_initialize(int functions) { return 0; }
|
||||
static int census_fns_enabled = CENSUS_NONE;
|
||||
|
||||
void census_shutdown() {}
|
||||
int census_initialize(int functions) {
|
||||
if (census_fns_enabled != CENSUS_NONE) {
|
||||
return 1;
|
||||
}
|
||||
if (functions != CENSUS_NONE) {
|
||||
return 1;
|
||||
} else {
|
||||
census_fns_enabled = functions;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void census_shutdown() { census_fns_enabled = CENSUS_NONE; }
|
||||
|
|
|
|||
|
|
@ -64,7 +64,9 @@ void grpc_init(void) {
|
|||
grpc_security_pre_init();
|
||||
grpc_iomgr_init();
|
||||
grpc_tracer_init("GRPC_TRACE");
|
||||
census_initialize(CENSUS_NONE);
|
||||
if (census_initialize(CENSUS_NONE)) {
|
||||
gpr_log(GPR_ERROR, "Could not initialize census.");
|
||||
}
|
||||
grpc_timers_global_init();
|
||||
}
|
||||
gpr_mu_unlock(&g_init_mu);
|
||||
|
|
|
|||
Loading…
Reference in New Issue