Fix: Multiple health monitoring fixes
[lttng-tools.git] / src / bin / lttng-sessiond / health.c
CommitLineData
44a5e5eb
DG
1/*
2 * Copyright (C) 2012 - David Goulet <dgoulet@efficios.com>
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License, version 2 only, as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc., 51
15 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 */
17
18#define _GNU_SOURCE
19#include <assert.h>
20#include <inttypes.h>
21#include <stdio.h>
22#include <stdlib.h>
23
24#include <common/error.h>
25
26#include "health.h"
27
28/*
29 * Check health of a specific health state counter.
30 *
31 * Return 0 if health is bad or else 1.
32 */
33int health_check_state(struct health_state *state)
34{
139ac872
MD
35 unsigned long current, last;
36 int ret = 1;
44a5e5eb
DG
37
38 assert(state);
39
139ac872 40 last = state->last;
44a5e5eb 41 current = uatomic_read(&state->current);
44a5e5eb
DG
42
43 /*
139ac872
MD
44 * Here are the conditions for a bad health. Either flag HEALTH_ERROR is
45 * set, or the progress counter is the same as the last one and we are NOT
46 * waiting for a poll() call.
44a5e5eb 47 */
139ac872
MD
48 if ((uatomic_read(&state->flags) & HEALTH_ERROR) ||
49 (current == last && !HEALTH_IS_IN_POLL(current))) {
50 /* error */
44a5e5eb 51 ret = 0;
44a5e5eb
DG
52 }
53
44a5e5eb
DG
54 DBG("Health state current %" PRIu64 ", last %" PRIu64 ", ret %d",
55 current, last, ret);
56
139ac872
MD
57 /*
58 * Update last counter. This value is and MUST be access only in this
59 * function.
60 */
61 state->last = current;
62
44a5e5eb
DG
63 return ret;
64}
This page took 0.026074 seconds and 4 git commands to generate.