+ return retval;
+}
+
+/*
+ * Check health of a specific health type. Note that if a thread has not yet
+ * initialize its health subsystem or has quit, it's considered in a good
+ * state.
+ *
+ * Return 0 if health is bad or else 1.
+ */
+int health_check_state(enum health_type type)
+{
+ int retval = 1;
+ struct health_state *state;
+
+ assert(type < HEALTH_NUM_TYPE);
+
+ state_lock();
+
+ cds_list_for_each_entry(state, &health_state_list.head, node) {
+ int ret;
+
+ if (state->type != type) {
+ continue;
+ }
+
+ ret = validate_state(state);
+ if (!ret) {
+ retval = 0;
+ goto end;
+ }
+ }
+
+ /* Check the global state since some state might not be visible anymore. */
+ if (global_error_state[type] & HEALTH_ERROR) {
+ retval = 0;
+ }
+
+end:
+ state_unlock();
+
+ DBG("Health check for type %d is %s", (int) type,
+ (retval == 0) ? "BAD" : "GOOD");
+ return retval;
+}
+
+/*
+ * Init health state.
+ */
+void health_register(enum health_type type)
+{
+ assert(type < HEALTH_NUM_TYPE);
+
+ /* Init TLS state. */
+ uatomic_set(&URCU_TLS(health_state).last, 0);
+ uatomic_set(&URCU_TLS(health_state).last_time.tv_sec, 0);
+ uatomic_set(&URCU_TLS(health_state).last_time.tv_nsec, 0);
+ uatomic_set(&URCU_TLS(health_state).current, 0);
+ uatomic_set(&URCU_TLS(health_state).flags, 0);
+ uatomic_set(&URCU_TLS(health_state).type, type);