aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Alistair Veitch <aveitch@google.com>2015-06-01 10:45:54 -0700
committerGravatar Alistair Veitch <aveitch@google.com>2015-06-01 10:45:54 -0700
commit269676209ead4602e0cb0bd02ebf378dcd5df7b3 (patch)
tree796ee30af5ed69cd51ec1c76ed5f099aab1c4afc
parent9d48ebfdc3eae8f68dcf1f60490ca14f5ca49aee (diff)
add init checks
-rw-r--r--include/grpc/census.h4
-rw-r--r--src/core/census/initialize.c16
-rw-r--r--src/core/surface/init.c4
3 files changed, 20 insertions, 4 deletions
diff --git a/include/grpc/census.h b/include/grpc/census.h
index a02724ed75..9b89f9fce9 100644
--- a/include/grpc/census.h
+++ b/include/grpc/census.h
@@ -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();
diff --git a/src/core/census/initialize.c b/src/core/census/initialize.c
index d72c08b91c..057ac78ee7 100644
--- a/src/core/census/initialize.c
+++ b/src/core/census/initialize.c
@@ -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; }
diff --git a/src/core/surface/init.c b/src/core/surface/init.c
index 5cd5d9197f..ac6871c6f2 100644
--- a/src/core/surface/init.c
+++ b/src/core/surface/init.c
@@ -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);