+
+/*
+ * Init health state.
+ */
+void health_register(struct health_app *ha, int type)
+{
+ assert(type < ha->nr_types);
+
+ /* 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(ha);
+ cds_list_add(&URCU_TLS(health_state).node, &ha->list);
+ state_unlock(ha);
+}
+
+/*
+ * Remove node from global list.
+ */
+void health_unregister(struct health_app *ha)
+{
+ state_lock(ha);
+ /*
+ * 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(&ha->flags[URCU_TLS(health_state).type],
+ HEALTH_ERROR);
+ }
+ cds_list_del(&URCU_TLS(health_state).node);
+ state_unlock(ha);
+}
+
+/*
+ * Initiliazie health check subsytem. This should be called before any health
+ * register occurs.
+ */
+void health_init(struct health_app *ha)
+{
+ /*
+ * Get the maximum value between the default delta value and the TCP
+ * timeout with a safety net of the default health check delta.
+ */
+ ha->time_delta.tv_sec = max_t(unsigned long,
+ lttcomm_inet_tcp_timeout + DEFAULT_HEALTH_CHECK_DELTA_S,
+ ha->time_delta.tv_sec);
+ DBG("Health check time delta in seconds set to %lu",
+ ha->time_delta.tv_sec);
+}