2 * Copyright (C) 2012 - David Goulet <dgoulet@efficios.com>
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.
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
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.
22 #include <urcu/uatomic.h>
25 * These are the value added to the current state depending of the position in
26 * the thread where is either waiting on a poll() or running in the code.
28 #define HEALTH_POLL_VALUE 1
29 #define HEALTH_CODE_VALUE 2
31 #define HEALTH_IS_IN_POLL(x) (x % HEALTH_CODE_VALUE)
32 #define HEALTH_IS_IN_CODE(x) (x % HEALTH_POLL_VALUE)
39 /* Health state counters for the client command thread */
40 extern struct health_state health_thread_cmd
;
42 /* Health state counters for the application registration thread */
43 extern struct health_state health_thread_app_reg
;
45 /* Health state counters for the kernel thread */
46 extern struct health_state health_thread_kernel
;
49 * Update current counter by 1 to indicate that the thread is in a blocking
50 * state cause by a poll().
52 static inline void health_poll_update(struct health_state
*state
)
56 uatomic_add(&state
->current
, HEALTH_POLL_VALUE
);
60 * Update current counter by 2 which indicates that we are currently running in
61 * a thread and NOT blocked at a poll().
63 static inline void health_code_update(struct health_state
*state
)
67 uatomic_add(&state
->current
, HEALTH_CODE_VALUE
);
71 * Reset health state. A value of zero indicate a bad health state.
73 static inline void health_reset(struct health_state
*state
)
77 uatomic_set(&state
->current
, 0);
78 uatomic_set(&state
->last
, 0);
84 static inline void health_init(struct health_state
*state
)
88 uatomic_set(&state
->last
, 0);
89 uatomic_set(&state
->current
, HEALTH_CODE_VALUE
);
92 int health_check_state(struct health_state
*state
);
94 #endif /* _HEALTH_H */