1 #ifndef HEALTH_INTERNAL_H
2 #define HEALTH_INTERNAL_H
5 * Copyright (C) 2012 - David Goulet <dgoulet@efficios.com>
6 * Copyright (C) 2013 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License, version 2 only, as
10 * published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc., 51
19 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include <urcu/tls-compat.h>
26 #include <urcu/uatomic.h>
27 #include <urcu/list.h>
30 * These are the value added to the current state depending of the position in
31 * the thread where is either waiting on a poll() or running in the code.
33 #define HEALTH_POLL_VALUE (1UL << 0)
34 #define HEALTH_CODE_VALUE (1UL << 1)
36 #define HEALTH_IS_IN_POLL(x) ((x) & HEALTH_POLL_VALUE)
41 HEALTH_ERROR
= (1U << 0),
46 * last counter and last_time are only read and updated by the health_check
47 * thread (single updater).
50 struct timespec last_time
;
53 * current and flags are updated by multiple threads concurrently.
55 unsigned long current
; /* progress counter, updated atomically */
56 enum health_flags flags
; /* other flags, updated atomically */
57 int type
; /* Indicates the nature of the thread. */
58 /* Node of the global TLS state list. */
59 struct cds_list_head node
;
66 struct health_comm_msg
{
68 uint32_t cmd
; /* enum health_cmd */
71 struct health_comm_reply
{
75 /* Declare TLS health state. */
76 extern DECLARE_URCU_TLS(struct health_state
, health_state
);
79 * Update current counter by 1 to indicate that the thread entered or left a
80 * blocking state caused by a poll(). If the counter's value is not an even
81 * number (meaning a code execution flow), an assert() is raised.
83 static inline void health_poll_entry(void)
85 /* Code MUST be in code execution state which is an even number. */
86 assert(!(uatomic_read(&URCU_TLS(health_state
).current
)
87 & HEALTH_POLL_VALUE
));
89 uatomic_add(&URCU_TLS(health_state
).current
, HEALTH_POLL_VALUE
);
93 * Update current counter by 1 indicating the exit of a poll or blocking call.
94 * If the counter's value is not an odd number (a poll execution), an assert()
97 static inline void health_poll_exit(void)
99 /* Code MUST be in poll execution state which is an odd number. */
100 assert(uatomic_read(&URCU_TLS(health_state
).current
)
101 & HEALTH_POLL_VALUE
);
103 uatomic_add(&URCU_TLS(health_state
).current
, HEALTH_POLL_VALUE
);
107 * Update current counter by 2 indicates progress in execution of a
110 static inline void health_code_update(void)
112 uatomic_add(&URCU_TLS(health_state
).current
, HEALTH_CODE_VALUE
);
116 * Set health "error" flag.
118 static inline void health_error(void)
120 uatomic_or(&URCU_TLS(health_state
).flags
, HEALTH_ERROR
);
123 struct health_app
*health_app_create(int nr_types
);
124 void health_app_destroy(struct health_app
*ha
);
125 int health_check_state(struct health_app
*ha
, int type
);
126 void health_register(struct health_app
*ha
, int type
);
127 void health_unregister(struct health_app
*ha
);
129 #endif /* HEALTH_INTERNAL_H */
This page took 0.03683 seconds and 6 git commands to generate.