Go to the documentation of this file.
6 #ifndef ABTI_ERROR_H_INCLUDED
7 #define ABTI_ERROR_H_INCLUDED
12 #define ABTI_ASSERT(cond) \
14 if (ABTI_IS_ERROR_CHECK_ENABLED) { \
19 #define ABTI_STATIC_ASSERT(cond) \
21 ((void)sizeof(char[2 * !!(cond)-1])); \
24 #ifdef ABT_CONFIG_PRINT_ABT_ERRNO
25 #define ABTI_IS_PRINT_ABT_ERRNO_ENABLED 1
27 #define ABTI_IS_PRINT_ABT_ERRNO_ENABLED 0
30 #define HANDLE_WARNING(msg) \
32 if (ABTI_IS_PRINT_ABT_ERRNO_ENABLED) { \
33 fprintf(stderr, "[%s:%d] %s\n", __FILE__, __LINE__, msg); \
37 #define HANDLE_ERROR(msg) \
39 if (ABTI_IS_PRINT_ABT_ERRNO_ENABLED) { \
40 fprintf(stderr, "[%s:%d] %s\n", __FILE__, __LINE__, msg); \
44 #define HANDLE_ERROR_WITH_CODE(msg, n) \
46 if (ABTI_IS_PRINT_ABT_ERRNO_ENABLED) { \
47 fprintf(stderr, "[%s:%d] %s: %d\n", __FILE__, __LINE__, msg, n); \
51 #define HANDLE_ERROR_FUNC_WITH_CODE(n) \
53 if (ABTI_IS_PRINT_ABT_ERRNO_ENABLED) { \
54 fprintf(stderr, "[%s:%d] %s: %d\n", __FILE__, __LINE__, __func__, \
59 #define ABTI_SETUP_GLOBAL(pp_global) \
61 ABTI_global *p_global_tmp = ABTI_global_get_global_or_null(); \
62 if (ABTI_IS_ERROR_CHECK_ENABLED && \
63 ABTU_unlikely(p_global_tmp == NULL)) { \
64 HANDLE_ERROR_FUNC_WITH_CODE(ABT_ERR_UNINITIALIZED); \
65 return ABT_ERR_UNINITIALIZED; \
67 ABTI_global **pp_global_tmp = (pp_global); \
68 if (pp_global_tmp) { \
69 *pp_global_tmp = p_global_tmp; \
73 #define ABTI_SETUP_LOCAL_XSTREAM(pp_local_xstream) \
75 ABTI_xstream *p_local_xstream_tmp = \
76 ABTI_local_get_xstream_or_null(ABTI_local_get_local()); \
77 if (ABTI_IS_EXT_THREAD_ENABLED && \
78 ABTU_unlikely(p_local_xstream_tmp == NULL)) { \
79 HANDLE_ERROR_FUNC_WITH_CODE(ABT_ERR_INV_XSTREAM); \
80 return ABT_ERR_INV_XSTREAM; \
82 ABTI_xstream **pp_local_xstream_tmp = (pp_local_xstream); \
83 if (pp_local_xstream_tmp) { \
84 *pp_local_xstream_tmp = p_local_xstream_tmp; \
88 #define ABTI_SETUP_LOCAL_YTHREAD(pp_local_xstream, pp_ythread) \
90 ABTI_xstream *p_local_xstream_tmp = \
91 ABTI_local_get_xstream_or_null(ABTI_local_get_local()); \
92 if (ABTI_IS_ERROR_CHECK_ENABLED && ABTI_IS_EXT_THREAD_ENABLED && \
93 ABTU_unlikely(p_local_xstream_tmp == NULL)) { \
94 HANDLE_ERROR_FUNC_WITH_CODE(ABT_ERR_INV_XSTREAM); \
95 return ABT_ERR_INV_XSTREAM; \
97 ABTI_xstream **pp_local_xstream_tmp = (pp_local_xstream); \
98 if (pp_local_xstream_tmp) { \
99 *pp_local_xstream_tmp = p_local_xstream_tmp; \
101 ABTI_thread *p_thread_tmp = p_local_xstream_tmp->p_thread; \
102 if (ABTI_IS_ERROR_CHECK_ENABLED && \
104 !(p_thread_tmp->type & ABTI_THREAD_TYPE_YIELDABLE))) { \
105 HANDLE_ERROR_FUNC_WITH_CODE(ABT_ERR_INV_THREAD); \
106 return ABT_ERR_INV_THREAD; \
108 ABTI_ythread **pp_ythread_tmp = (pp_ythread); \
109 if (pp_ythread_tmp) { \
110 *pp_ythread_tmp = ABTI_thread_get_ythread(p_thread_tmp); \
114 #define ABTI_HANDLE_ERROR(n) \
116 HANDLE_ERROR_FUNC_WITH_CODE(n); \
120 #define ABTI_CHECK_ERROR(abt_errno) \
122 int abt_errno_ = (abt_errno); \
123 if (ABTI_IS_ERROR_CHECK_ENABLED && \
124 ABTU_unlikely(abt_errno_ != ABT_SUCCESS)) { \
125 HANDLE_ERROR_FUNC_WITH_CODE(abt_errno_); \
130 #define ABTI_CHECK_TRUE(cond, abt_errno) \
132 if (ABTI_IS_ERROR_CHECK_ENABLED && ABTU_unlikely(!(cond))) { \
133 int abt_errno_ = (abt_errno); \
134 HANDLE_ERROR_FUNC_WITH_CODE(abt_errno_); \
139 #define ABTI_CHECK_YIELDABLE(p_thread, pp_ythread, abt_errno) \
141 ABTI_thread *p_tmp = (p_thread); \
142 if (ABTI_IS_ERROR_CHECK_ENABLED && \
143 ABTU_unlikely(!(p_tmp->type & ABTI_THREAD_TYPE_YIELDABLE))) { \
144 int abt_errno_ = (abt_errno); \
145 HANDLE_ERROR_FUNC_WITH_CODE(abt_errno_); \
148 *(pp_ythread) = ABTI_thread_get_ythread(p_tmp); \
151 #define ABTI_CHECK_TRUE_MSG(cond, abt_errno, msg) \
153 if (ABTI_IS_ERROR_CHECK_ENABLED && ABTU_unlikely(!(cond))) { \
155 return (abt_errno); \
159 #define ABTI_CHECK_NULL_XSTREAM_PTR(p) \
161 if (ABTI_IS_ERROR_CHECK_ENABLED && \
162 ABTU_unlikely(p == (ABTI_xstream *)NULL)) { \
163 HANDLE_ERROR_FUNC_WITH_CODE(ABT_ERR_INV_XSTREAM); \
164 return ABT_ERR_INV_XSTREAM; \
168 #define ABTI_CHECK_NULL_POOL_PTR(p) \
170 if (ABTI_IS_ERROR_CHECK_ENABLED && \
171 ABTU_unlikely(p == (ABTI_pool *)NULL)) { \
172 HANDLE_ERROR_FUNC_WITH_CODE(ABT_ERR_INV_POOL); \
173 return ABT_ERR_INV_POOL; \
177 #define ABTI_CHECK_NULL_SCHED_PTR(p) \
179 if (ABTI_IS_ERROR_CHECK_ENABLED && \
180 ABTU_unlikely(p == (ABTI_sched *)NULL)) { \
181 HANDLE_ERROR_FUNC_WITH_CODE(ABT_ERR_INV_SCHED); \
182 return ABT_ERR_INV_SCHED; \
186 #define ABTI_CHECK_NULL_SCHED_CONFIG_PTR(p) \
188 if (ABTI_IS_ERROR_CHECK_ENABLED && \
189 ABTU_unlikely(p == (ABTI_sched_config *)NULL)) { \
190 HANDLE_ERROR_FUNC_WITH_CODE(ABT_ERR_INV_SCHED_CONFIG); \
191 return ABT_ERR_INV_SCHED_CONFIG; \
195 #define ABTI_CHECK_NULL_THREAD_PTR(p) \
197 if (ABTI_IS_ERROR_CHECK_ENABLED && \
198 ABTU_unlikely(p == (ABTI_thread *)NULL)) { \
199 HANDLE_ERROR_FUNC_WITH_CODE(ABT_ERR_INV_THREAD); \
200 return ABT_ERR_INV_THREAD; \
204 #define ABTI_CHECK_NULL_YTHREAD_PTR(p) \
206 if (ABTI_IS_ERROR_CHECK_ENABLED && \
207 ABTU_unlikely(p == (ABTI_ythread *)NULL)) { \
208 HANDLE_ERROR_FUNC_WITH_CODE(ABT_ERR_INV_THREAD); \
209 return ABT_ERR_INV_THREAD; \
213 #define ABTI_CHECK_NULL_THREAD_ATTR_PTR(p) \
215 if (ABTI_IS_ERROR_CHECK_ENABLED && \
216 ABTU_unlikely(p == (ABTI_thread_attr *)NULL)) { \
217 HANDLE_ERROR_FUNC_WITH_CODE(ABT_ERR_INV_THREAD_ATTR); \
218 return ABT_ERR_INV_THREAD_ATTR; \
222 #define ABTI_CHECK_NULL_TASK_PTR(p) \
224 if (ABTI_IS_ERROR_CHECK_ENABLED && \
225 ABTU_unlikely(p == (ABTI_thread *)NULL)) { \
226 HANDLE_ERROR_FUNC_WITH_CODE(ABT_ERR_INV_TASK); \
227 return ABT_ERR_INV_TASK; \
231 #define ABTI_CHECK_NULL_KEY_PTR(p) \
233 if (ABTI_IS_ERROR_CHECK_ENABLED && \
234 ABTU_unlikely(p == (ABTI_key *)NULL)) { \
235 HANDLE_ERROR_FUNC_WITH_CODE(ABT_ERR_INV_KEY); \
236 return ABT_ERR_INV_KEY; \
240 #define ABTI_CHECK_NULL_MUTEX_PTR(p) \
242 if (ABTI_IS_ERROR_CHECK_ENABLED && \
243 ABTU_unlikely(p == (ABTI_mutex *)NULL)) { \
244 HANDLE_ERROR_FUNC_WITH_CODE(ABT_ERR_INV_MUTEX); \
245 return ABT_ERR_INV_MUTEX; \
249 #define ABTI_CHECK_NULL_MUTEX_ATTR_PTR(p) \
251 if (ABTI_IS_ERROR_CHECK_ENABLED && \
252 ABTU_unlikely(p == (ABTI_mutex_attr *)NULL)) { \
253 HANDLE_ERROR_FUNC_WITH_CODE(ABT_ERR_INV_MUTEX_ATTR); \
254 return ABT_ERR_INV_MUTEX_ATTR; \
258 #define ABTI_CHECK_NULL_COND_PTR(p) \
260 if (ABTI_IS_ERROR_CHECK_ENABLED && \
261 ABTU_unlikely(p == (ABTI_cond *)NULL)) { \
262 HANDLE_ERROR_FUNC_WITH_CODE(ABT_ERR_INV_COND); \
263 return ABT_ERR_INV_COND; \
267 #define ABTI_CHECK_NULL_RWLOCK_PTR(p) \
269 if (ABTI_IS_ERROR_CHECK_ENABLED && \
270 ABTU_unlikely(p == (ABTI_rwlock *)NULL)) { \
271 HANDLE_ERROR_FUNC_WITH_CODE(ABT_ERR_INV_RWLOCK); \
272 return ABT_ERR_INV_RWLOCK; \
276 #define ABTI_CHECK_NULL_FUTURE_PTR(p) \
278 if (ABTI_IS_ERROR_CHECK_ENABLED && \
279 ABTU_unlikely(p == (ABTI_future *)NULL)) { \
280 HANDLE_ERROR_FUNC_WITH_CODE(ABT_ERR_INV_FUTURE); \
281 return ABT_ERR_INV_FUTURE; \
285 #define ABTI_CHECK_NULL_EVENTUAL_PTR(p) \
287 if (ABTI_IS_ERROR_CHECK_ENABLED && \
288 ABTU_unlikely(p == (ABTI_eventual *)NULL)) { \
289 HANDLE_ERROR_FUNC_WITH_CODE(ABT_ERR_INV_EVENTUAL); \
290 return ABT_ERR_INV_EVENTUAL; \
294 #define ABTI_CHECK_NULL_BARRIER_PTR(p) \
296 if (ABTI_IS_ERROR_CHECK_ENABLED && \
297 ABTU_unlikely(p == (ABTI_barrier *)NULL)) { \
298 HANDLE_ERROR_FUNC_WITH_CODE(ABT_ERR_INV_BARRIER); \
299 return ABT_ERR_INV_BARRIER; \
303 #define ABTI_CHECK_NULL_XSTREAM_BARRIER_PTR(p) \
305 if (ABTI_IS_ERROR_CHECK_ENABLED && \
306 ABTU_unlikely(p == (ABTI_xstream_barrier *)NULL)) { \
307 HANDLE_ERROR_FUNC_WITH_CODE(ABT_ERR_INV_XSTREAM_BARRIER); \
308 return ABT_ERR_INV_XSTREAM_BARRIER; \
312 #define ABTI_CHECK_NULL_TIMER_PTR(p) \
314 if (ABTI_IS_ERROR_CHECK_ENABLED && \
315 ABTU_unlikely(p == (ABTI_timer *)NULL)) { \
316 HANDLE_ERROR_FUNC_WITH_CODE(ABT_ERR_INV_TIMER); \
317 return ABT_ERR_INV_TIMER; \
321 #define ABTI_CHECK_NULL_TOOL_CONTEXT_PTR(p) \
323 if (ABTI_IS_ERROR_CHECK_ENABLED && \
324 ABTU_unlikely(p == (ABTI_tool_context *)NULL)) { \
325 HANDLE_ERROR_FUNC_WITH_CODE(ABT_ERR_INV_TOOL_CONTEXT); \
326 return ABT_ERR_INV_TOOL_CONTEXT; \