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.
24 #include <urcu/tls-compat.h>
25 #include <urcu/uatomic.h>
26 #include <urcu/list.h>
29 * These are the value added to the current state depending of the position in
30 * the thread where is either waiting on a poll() or running in the code.
32 #define HEALTH_POLL_VALUE (1UL << 0)
33 #define HEALTH_CODE_VALUE (1UL << 1)
35 #define HEALTH_IS_IN_POLL(x) ((x) & HEALTH_POLL_VALUE)
38 HEALTH_ERROR
= (1U << 0),
43 HEALTH_TYPE_APP_MANAGE
= 1,
44 HEALTH_TYPE_APP_REG
= 2,
45 HEALTH_TYPE_KERNEL
= 3,
46 HEALTH_TYPE_CONSUMER
= 4,
51 struct health_tls_state_list
{
52 struct cds_list_head head
;
57 * last counter and last_time are only read and updated by the health_check
58 * thread (single updater).
61 struct timespec last_time
;
64 * current and flags are updated by multiple threads concurrently.
66 unsigned long current
; /* progress counter, updated atomically */
67 enum health_flags flags
; /* other flags, updated atomically */
68 enum health_type type
; /* Indicates the nature of the thread. */
69 /* Node of the global TLS state list. */
70 struct cds_list_head node
;
73 /* Declare TLS health state. */
74 extern DECLARE_URCU_TLS(struct health_state
, health_state
);
77 * Update current counter by 1 to indicate that the thread entered or left a
78 * blocking state caused by a poll(). If the counter's value is not an even
79 * number (meaning a code execution flow), an assert() is raised.
81 static inline void health_poll_entry(void)
83 /* Code MUST be in code execution state which is an even number. */
84 assert(!(uatomic_read(&URCU_TLS(health_state
).current
)
85 & HEALTH_POLL_VALUE
));
87 uatomic_add(&URCU_TLS(health_state
).current
, HEALTH_POLL_VALUE
);
91 * Update current counter by 1 indicating the exit of a poll or blocking call.
92 * If the counter's value is not an odd number (a poll execution), an assert()
95 static inline void health_poll_exit(void)
97 /* Code MUST be in poll execution state which is an odd number. */
98 assert(uatomic_read(&URCU_TLS(health_state
).current
)
101 uatomic_add(&URCU_TLS(health_state
).current
, HEALTH_POLL_VALUE
);
105 * Update current counter by 2 indicates progress in execution of a
108 static inline void health_code_update(void)
110 uatomic_add(&URCU_TLS(health_state
).current
, HEALTH_CODE_VALUE
);
114 * Set health "error" flag.
116 static inline void health_error(void)
118 uatomic_or(&URCU_TLS(health_state
).flags
, HEALTH_ERROR
);
121 int health_check_state(enum health_type type
);
122 void health_register(enum health_type type
);
123 void health_unregister(void);
125 #endif /* _HEALTH_H */
This page took 0.04846 seconds and 4 git commands to generate.