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 (1UL << 0)
29 #define HEALTH_CODE_VALUE (1UL << 1)
31 #define HEALTH_IS_IN_POLL(x) ((x) & HEALTH_POLL_VALUE)
34 HEALTH_EXIT
= (1U << 0),
35 HEALTH_ERROR
= (1U << 1),
40 * last counter is only read and updated by the health_check
41 * thread (single updater).
45 * current and flags are updated by multiple threads concurrently.
47 unsigned long current
; /* progress counter, updated atomically */
48 enum health_flags flags
; /* other flags, updated atomically */
51 /* Health state counters for the client command thread */
52 extern struct health_state health_thread_cmd
;
54 /* Health state counters for the application management thread */
55 extern struct health_state health_thread_app_manage
;
57 /* Health state counters for the application registration thread */
58 extern struct health_state health_thread_app_reg
;
60 /* Health state counters for the kernel thread */
61 extern struct health_state health_thread_kernel
;
64 * Update current counter by 1 to indicate that the thread entered or
65 * left a blocking state caused by a poll().
67 static inline void health_poll_update(struct health_state
*state
)
70 uatomic_add(&state
->current
, HEALTH_POLL_VALUE
);
74 * Update current counter by 2 indicates progress in execution of a
77 static inline void health_code_update(struct health_state
*state
)
80 uatomic_add(&state
->current
, HEALTH_CODE_VALUE
);
84 * Set health "exit" flag.
86 static inline void health_exit(struct health_state
*state
)
89 uatomic_or(&state
->flags
, HEALTH_EXIT
);
93 * Set health "error" flag.
95 static inline void health_error(struct health_state
*state
)
98 uatomic_or(&state
->flags
, HEALTH_ERROR
);
104 static inline void health_init(struct health_state
*state
)
107 uatomic_set(&state
->last
, 0);
108 uatomic_set(&state
->current
, 0);
109 uatomic_set(&state
->flags
, 0);
112 int health_check_state(struct health_state
*state
);
114 #endif /* _HEALTH_H */