Skip to content

Commit

Permalink
add init checks
Browse files Browse the repository at this point in the history
  • Loading branch information
a-veitch committed Jun 1, 2015
1 parent 9d48ebf commit 2696762
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
4 changes: 3 additions & 1 deletion include/grpc/census.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
16 changes: 14 additions & 2 deletions src/core/census/initialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
4 changes: 3 additions & 1 deletion src/core/surface/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 2696762

Please sign in to comment.