+
+/*
+ * Init health state.
+ */
+void health_register(enum health_type type)
+{
+ struct health_state *state;
+
+ 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);
+
+ /* Add it to the global TLS state list. */
+ state_lock();
+ state = find_health_state(type);
+ /*
+ * Duplicates are not accepted, since lookups don't handle them at the
+ * moment.
+ */
+ assert(!state);
+
+ cds_list_add(&URCU_TLS(health_state).node, &health_state_list.head);
+ state_unlock();
+}
+
+/*
+ * Remove node from global list.
+ */
+void health_unregister(void)
+{
+ state_lock();
+ /*
+ * On error, set the global_error_state since we are about to remove
+ * the node from the global list.
+ */
+ if (uatomic_read(&URCU_TLS(health_state).flags) & HEALTH_ERROR) {
+ uatomic_set(&global_error_state[URCU_TLS(health_state).type],
+ HEALTH_ERROR);
+ }
+ cds_list_del(&URCU_TLS(health_state).node);
+ state_unlock();
+}