*/
#define _LGPL_SOURCE
-#include <algorithm>
-#include <inttypes.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <time.h>
-
#include <common/defaults.hpp>
#include <common/error.hpp>
#include <common/macros.hpp>
#include <lttng/health-internal.hpp>
+#include <algorithm>
+#include <inttypes.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+
/*
* An application-specific error state for unregistered thread keeps
* track of thread errors. A thread reporting a health error, normally
};
/* Define TLS health state. */
-DEFINE_URCU_TLS(struct health_state, health_state);
+thread_local struct health_state health_state;
/*
* Initialize health check subsytem.
*/
-static
-void health_init(struct health_app *ha)
+static 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 = std::max<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);
+ 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);
}
struct health_app *health_app_create(int nr_types)
{
struct health_app *ha;
- ha = (health_app *) zmalloc(sizeof(*ha));
+ ha = zmalloc<health_app>();
if (!ha) {
- return NULL;
+ return nullptr;
}
- ha->flags = (health_flags *) zmalloc(sizeof(*ha->flags) * nr_types);
+ ha->flags = calloc<health_flags>(nr_types);
if (!ha->flags) {
goto error_flags;
}
CDS_INIT_LIST_HEAD(&ha->list);
- pthread_mutex_init(&ha->lock, NULL);
+ pthread_mutex_init(&ha->lock, nullptr);
ha->nr_types = nr_types;
ha->time_delta.tv_sec = DEFAULT_HEALTH_CHECK_DELTA_S;
ha->time_delta.tv_nsec = DEFAULT_HEALTH_CHECK_DELTA_NS;
error_flags:
free(ha);
- return NULL;
+ return nullptr;
}
void health_app_destroy(struct health_app *ha)
/*
* Set time difference in res from time_a and time_b.
*/
-static void time_diff(const struct timespec *time_a,
- const struct timespec *time_b, struct timespec *res)
+static void
+time_diff(const struct timespec *time_a, const struct timespec *time_b, struct timespec *res)
{
if (time_a->tv_nsec - time_b->tv_nsec < 0) {
res->tv_sec = time_a->tv_sec - time_b->tv_sec - 1;
* Return true if time_a - time_b > diff, else false.
*/
static int time_diff_gt(const struct timespec *time_a,
- const struct timespec *time_b, const struct timespec *diff)
+ const struct timespec *time_b,
+ const struct timespec *diff)
{
struct timespec res;
state->last = current;
memcpy(&state->last_time, ¤t_time, sizeof(current_time));
} else {
- if (time_diff_gt(¤t_time, &state->last_time,
- &ha->time_delta)) {
+ if (time_diff_gt(¤t_time, &state->last_time, &ha->time_delta)) {
if (current == last && !HEALTH_IS_IN_POLL(current)) {
/* error */
retval = 0;
}
end:
- DBG("Health state current %lu, last %lu, ret %d",
- current, last, ret);
+ DBG("Health state current %lu, last %lu, ret %d", current, last, ret);
return retval;
}
state_lock(ha);
- cds_list_for_each_entry(state, &ha->list, node) {
+ cds_list_for_each_entry (state, &ha->list, node) {
int ret;
if (state->type != type) {
end:
state_unlock(ha);
- DBG("Health check for type %d is %s", (int) type,
- (retval == 0) ? "BAD" : "GOOD");
+ DBG("Health check for type %d is %s", (int) type, (retval == 0) ? "BAD" : "GOOD");
return retval;
}
LTTNG_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, (health_flags) 0);
- uatomic_set(&URCU_TLS(health_state).type, type);
+ uatomic_set(&health_state.last, 0);
+ uatomic_set(&health_state.last_time.tv_sec, 0);
+ uatomic_set(&health_state.last_time.tv_nsec, 0);
+ uatomic_set(&health_state.current, 0);
+ uatomic_set(&health_state.flags, (health_flags) 0);
+ uatomic_set(&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);
+ cds_list_add(&health_state.node, &ha->list);
state_unlock(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);
+ if (uatomic_read(&health_state.flags) & HEALTH_ERROR) {
+ uatomic_set(&ha->flags[health_state.type], HEALTH_ERROR);
}
- cds_list_del(&URCU_TLS(health_state).node);
+ cds_list_del(&health_state.node);
state_unlock(ha);
}