ARGOBOTS
dce6e727ffc4ca5b3ffc04cb9517c6689be51ec5
src
include
abti_error.h
Go to the documentation of this file.
1
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2
/*
3
* See COPYRIGHT in top-level directory.
4
*/
5
6
#ifndef ABTI_ERROR_H_INCLUDED
7
#define ABTI_ERROR_H_INCLUDED
8
9
#include <assert.h>
10
#include <
abt_config.h
>
11
12
#define ABTI_ASSERT(cond) \
13
do { \
14
if (ABTI_IS_ERROR_CHECK_ENABLED) { \
15
assert(cond); \
16
} \
17
} while (0)
18
19
#define ABTI_UB_ASSERT(cond) \
20
do { \
21
if (ABTI_IS_UB_ASSERT_ENABLED) { \
22
ABTI_ASSERT(cond); \
23
} \
24
} while (0)
25
26
#define ABTI_UB_ASSERT_BOOL(bool_val) \
27
do { \
28
if (ABTI_IS_UB_ASSERT_ENABLED) { \
29
ABT_bool bool_val_tmp = (bool_val); \
30
ABTI_ASSERT(bool_val_tmp == ABT_TRUE || \
31
bool_val_tmp == ABT_FALSE); \
32
} \
33
} while (0)
34
35
#define ABTI_STATIC_ASSERT(cond) \
36
do { \
37
((void)sizeof(char[2 * !!(cond)-1])); \
38
} while (0)
39
40
#ifdef ABT_CONFIG_PRINT_ABT_ERRNO
41
#define ABTI_IS_PRINT_ABT_ERRNO_ENABLED 1
42
#else
43
#define ABTI_IS_PRINT_ABT_ERRNO_ENABLED 0
44
#endif
45
46
#define HANDLE_WARNING(msg) \
47
do { \
48
if (ABTI_IS_PRINT_ABT_ERRNO_ENABLED) { \
49
fprintf(stderr, "[%s:%d] %s\n", __FILE__, __LINE__, msg); \
50
} \
51
} while (0)
52
53
#define HANDLE_ERROR(msg) \
54
do { \
55
if (ABTI_IS_PRINT_ABT_ERRNO_ENABLED) { \
56
fprintf(stderr, "[%s:%d] %s\n", __FILE__, __LINE__, msg); \
57
} \
58
} while (0)
59
60
#define HANDLE_ERROR_WITH_CODE(msg, n) \
61
do { \
62
if (ABTI_IS_PRINT_ABT_ERRNO_ENABLED) { \
63
fprintf(stderr, "[%s:%d] %s: %d\n", __FILE__, __LINE__, msg, n); \
64
} \
65
} while (0)
66
67
#define HANDLE_ERROR_FUNC_WITH_CODE(n) \
68
do { \
69
if (ABTI_IS_PRINT_ABT_ERRNO_ENABLED) { \
70
fprintf(stderr, "[%s:%d] %s: %d\n", __FILE__, __LINE__, __func__, \
71
n); \
72
} \
73
} while (0)
74
75
#define ABTI_SETUP_GLOBAL(pp_global) \
76
do { \
77
ABTI_global *p_global_tmp = ABTI_global_get_global_or_null(); \
78
if (ABTI_IS_ERROR_CHECK_ENABLED && \
79
ABTU_unlikely(p_global_tmp == NULL)) { \
80
HANDLE_ERROR_FUNC_WITH_CODE(ABT_ERR_UNINITIALIZED); \
81
return ABT_ERR_UNINITIALIZED; \
82
} \
83
ABTI_global **pp_global_tmp = (pp_global); \
84
if (pp_global_tmp) { \
85
*pp_global_tmp = p_global_tmp; \
86
} \
87
} while (0)
88
89
#define ABTI_SETUP_LOCAL_XSTREAM(pp_local_xstream) \
90
do { \
91
ABTI_xstream *p_local_xstream_tmp = \
92
ABTI_local_get_xstream_or_null(ABTI_local_get_local()); \
93
if (ABTI_IS_EXT_THREAD_ENABLED && \
94
ABTU_unlikely(p_local_xstream_tmp == NULL)) { \
95
HANDLE_ERROR_FUNC_WITH_CODE(ABT_ERR_INV_XSTREAM); \
96
return ABT_ERR_INV_XSTREAM; \
97
} \
98
ABTI_xstream **pp_local_xstream_tmp = (pp_local_xstream); \
99
if (pp_local_xstream_tmp) { \
100
*pp_local_xstream_tmp = p_local_xstream_tmp; \
101
} \
102
} while (0)
103
104
#define ABTI_SETUP_LOCAL_YTHREAD(pp_local_xstream, pp_ythread) \
105
do { \
106
ABTI_xstream *p_local_xstream_tmp = \
107
ABTI_local_get_xstream_or_null(ABTI_local_get_local()); \
108
if (ABTI_IS_ERROR_CHECK_ENABLED && ABTI_IS_EXT_THREAD_ENABLED && \
109
ABTU_unlikely(p_local_xstream_tmp == NULL)) { \
110
HANDLE_ERROR_FUNC_WITH_CODE(ABT_ERR_INV_XSTREAM); \
111
return ABT_ERR_INV_XSTREAM; \
112
} \
113
ABTI_xstream **pp_local_xstream_tmp = (pp_local_xstream); \
114
if (pp_local_xstream_tmp) { \
115
*pp_local_xstream_tmp = p_local_xstream_tmp; \
116
} \
117
ABTI_thread *p_thread_tmp = p_local_xstream_tmp->p_thread; \
118
if (ABTI_IS_ERROR_CHECK_ENABLED && \
119
ABTU_unlikely( \
120
!(p_thread_tmp->type & ABTI_THREAD_TYPE_YIELDABLE))) { \
121
HANDLE_ERROR_FUNC_WITH_CODE(ABT_ERR_INV_THREAD); \
122
return ABT_ERR_INV_THREAD; \
123
} \
124
ABTI_ythread **pp_ythread_tmp = (pp_ythread); \
125
if (pp_ythread_tmp) { \
126
*pp_ythread_tmp = ABTI_thread_get_ythread(p_thread_tmp); \
127
} \
128
} while (0)
129
130
#define ABTI_HANDLE_ERROR(n) \
131
do { \
132
HANDLE_ERROR_FUNC_WITH_CODE(n); \
133
return n; \
134
} while (0)
135
136
#define ABTI_CHECK_ERROR(abt_errno) \
137
do { \
138
int abt_errno_ = (abt_errno); \
139
if (ABTI_IS_ERROR_CHECK_ENABLED && \
140
ABTU_unlikely(abt_errno_ != ABT_SUCCESS)) { \
141
HANDLE_ERROR_FUNC_WITH_CODE(abt_errno_); \
142
return abt_errno_; \
143
} \
144
} while (0)
145
146
#define ABTI_CHECK_TRUE(cond, abt_errno) \
147
do { \
148
if (ABTI_IS_ERROR_CHECK_ENABLED && ABTU_unlikely(!(cond))) { \
149
int abt_errno_ = (abt_errno); \
150
HANDLE_ERROR_FUNC_WITH_CODE(abt_errno_); \
151
return abt_errno_; \
152
} \
153
} while (0)
154
155
#define ABTI_CHECK_YIELDABLE(p_thread, pp_ythread, abt_errno) \
156
do { \
157
ABTI_thread *p_tmp = (p_thread); \
158
if (ABTI_IS_ERROR_CHECK_ENABLED && \
159
ABTU_unlikely(!(p_tmp->type & ABTI_THREAD_TYPE_YIELDABLE))) { \
160
int abt_errno_ = (abt_errno); \
161
HANDLE_ERROR_FUNC_WITH_CODE(abt_errno_); \
162
return abt_errno_; \
163
} \
164
*(pp_ythread) = ABTI_thread_get_ythread(p_tmp); \
165
} while (0)
166
167
#define ABTI_CHECK_TRUE_MSG(cond, abt_errno, msg) \
168
do { \
169
if (ABTI_IS_ERROR_CHECK_ENABLED && ABTU_unlikely(!(cond))) { \
170
HANDLE_ERROR(msg); \
171
return (abt_errno); \
172
} \
173
} while (0)
174
175
#define ABTI_CHECK_NULL_XSTREAM_PTR(p) \
176
do { \
177
if (ABTI_IS_ERROR_CHECK_ENABLED && \
178
ABTU_unlikely(p == (ABTI_xstream *)NULL)) { \
179
HANDLE_ERROR_FUNC_WITH_CODE(ABT_ERR_INV_XSTREAM); \
180
return ABT_ERR_INV_XSTREAM; \
181
} \
182
} while (0)
183
184
#define ABTI_CHECK_NULL_POOL_PTR(p) \
185
do { \
186
if (ABTI_IS_ERROR_CHECK_ENABLED && \
187
ABTU_unlikely(p == (ABTI_pool *)NULL)) { \
188
HANDLE_ERROR_FUNC_WITH_CODE(ABT_ERR_INV_POOL); \
189
return ABT_ERR_INV_POOL; \
190
} \
191
} while (0)
192
193
#define ABTI_CHECK_NULL_POOL_CONFIG_PTR(p) \
194
do { \
195
if (ABTI_IS_ERROR_CHECK_ENABLED && \
196
ABTU_unlikely(p == (ABTI_pool_config *)NULL)) { \
197
HANDLE_ERROR_FUNC_WITH_CODE(ABT_ERR_INV_POOL_CONFIG); \
198
return ABT_ERR_INV_POOL_CONFIG; \
199
} \
200
} while (0)
201
202
#define ABTI_CHECK_NULL_POOL_USER_DEF_PTR(p) \
203
do { \
204
if (ABTI_IS_ERROR_CHECK_ENABLED && \
205
ABTU_unlikely(p == (ABTI_pool_user_def *)NULL)) { \
206
HANDLE_ERROR_FUNC_WITH_CODE(ABT_ERR_INV_POOL_USER_DEF); \
207
return ABT_ERR_INV_POOL_USER_DEF; \
208
} \
209
} while (0)
210
211
#define ABTI_CHECK_NULL_SCHED_PTR(p) \
212
do { \
213
if (ABTI_IS_ERROR_CHECK_ENABLED && \
214
ABTU_unlikely(p == (ABTI_sched *)NULL)) { \
215
HANDLE_ERROR_FUNC_WITH_CODE(ABT_ERR_INV_SCHED); \
216
return ABT_ERR_INV_SCHED; \
217
} \
218
} while (0)
219
220
#define ABTI_CHECK_NULL_SCHED_CONFIG_PTR(p) \
221
do { \
222
if (ABTI_IS_ERROR_CHECK_ENABLED && \
223
ABTU_unlikely(p == (ABTI_sched_config *)NULL)) { \
224
HANDLE_ERROR_FUNC_WITH_CODE(ABT_ERR_INV_SCHED_CONFIG); \
225
return ABT_ERR_INV_SCHED_CONFIG; \
226
} \
227
} while (0)
228
229
#define ABTI_CHECK_NULL_THREAD_PTR(p) \
230
do { \
231
if (ABTI_IS_ERROR_CHECK_ENABLED && \
232
ABTU_unlikely(p == (ABTI_thread *)NULL)) { \
233
HANDLE_ERROR_FUNC_WITH_CODE(ABT_ERR_INV_THREAD); \
234
return ABT_ERR_INV_THREAD; \
235
} \
236
} while (0)
237
238
#define ABTI_CHECK_NULL_YTHREAD_PTR(p) \
239
do { \
240
if (ABTI_IS_ERROR_CHECK_ENABLED && \
241
ABTU_unlikely(p == (ABTI_ythread *)NULL)) { \
242
HANDLE_ERROR_FUNC_WITH_CODE(ABT_ERR_INV_THREAD); \
243
return ABT_ERR_INV_THREAD; \
244
} \
245
} while (0)
246
247
#define ABTI_CHECK_NULL_THREAD_ATTR_PTR(p) \
248
do { \
249
if (ABTI_IS_ERROR_CHECK_ENABLED && \
250
ABTU_unlikely(p == (ABTI_thread_attr *)NULL)) { \
251
HANDLE_ERROR_FUNC_WITH_CODE(ABT_ERR_INV_THREAD_ATTR); \
252
return ABT_ERR_INV_THREAD_ATTR; \
253
} \
254
} while (0)
255
256
#define ABTI_CHECK_NULL_TASK_PTR(p) \
257
do { \
258
if (ABTI_IS_ERROR_CHECK_ENABLED && \
259
ABTU_unlikely(p == (ABTI_thread *)NULL)) { \
260
HANDLE_ERROR_FUNC_WITH_CODE(ABT_ERR_INV_TASK); \
261
return ABT_ERR_INV_TASK; \
262
} \
263
} while (0)
264
265
#define ABTI_CHECK_NULL_KEY_PTR(p) \
266
do { \
267
if (ABTI_IS_ERROR_CHECK_ENABLED && \
268
ABTU_unlikely(p == (ABTI_key *)NULL)) { \
269
HANDLE_ERROR_FUNC_WITH_CODE(ABT_ERR_INV_KEY); \
270
return ABT_ERR_INV_KEY; \
271
} \
272
} while (0)
273
274
#define ABTI_CHECK_NULL_MUTEX_PTR(p) \
275
do { \
276
if (ABTI_IS_ERROR_CHECK_ENABLED && \
277
ABTU_unlikely(p == (ABTI_mutex *)NULL)) { \
278
HANDLE_ERROR_FUNC_WITH_CODE(ABT_ERR_INV_MUTEX); \
279
return ABT_ERR_INV_MUTEX; \
280
} \
281
} while (0)
282
283
#define ABTI_CHECK_NULL_MUTEX_ATTR_PTR(p) \
284
do { \
285
if (ABTI_IS_ERROR_CHECK_ENABLED && \
286
ABTU_unlikely(p == (ABTI_mutex_attr *)NULL)) { \
287
HANDLE_ERROR_FUNC_WITH_CODE(ABT_ERR_INV_MUTEX_ATTR); \
288
return ABT_ERR_INV_MUTEX_ATTR; \
289
} \
290
} while (0)
291
292
#define ABTI_CHECK_NULL_COND_PTR(p) \
293
do { \
294
if (ABTI_IS_ERROR_CHECK_ENABLED && \
295
ABTU_unlikely(p == (ABTI_cond *)NULL)) { \
296
HANDLE_ERROR_FUNC_WITH_CODE(ABT_ERR_INV_COND); \
297
return ABT_ERR_INV_COND; \
298
} \
299
} while (0)
300
301
#define ABTI_CHECK_NULL_RWLOCK_PTR(p) \
302
do { \
303
if (ABTI_IS_ERROR_CHECK_ENABLED && \
304
ABTU_unlikely(p == (ABTI_rwlock *)NULL)) { \
305
HANDLE_ERROR_FUNC_WITH_CODE(ABT_ERR_INV_RWLOCK); \
306
return ABT_ERR_INV_RWLOCK; \
307
} \
308
} while (0)
309
310
#define ABTI_CHECK_NULL_FUTURE_PTR(p) \
311
do { \
312
if (ABTI_IS_ERROR_CHECK_ENABLED && \
313
ABTU_unlikely(p == (ABTI_future *)NULL)) { \
314
HANDLE_ERROR_FUNC_WITH_CODE(ABT_ERR_INV_FUTURE); \
315
return ABT_ERR_INV_FUTURE; \
316
} \
317
} while (0)
318
319
#define ABTI_CHECK_NULL_EVENTUAL_PTR(p) \
320
do { \
321
if (ABTI_IS_ERROR_CHECK_ENABLED && \
322
ABTU_unlikely(p == (ABTI_eventual *)NULL)) { \
323
HANDLE_ERROR_FUNC_WITH_CODE(ABT_ERR_INV_EVENTUAL); \
324
return ABT_ERR_INV_EVENTUAL; \
325
} \
326
} while (0)
327
328
#define ABTI_CHECK_NULL_BARRIER_PTR(p) \
329
do { \
330
if (ABTI_IS_ERROR_CHECK_ENABLED && \
331
ABTU_unlikely(p == (ABTI_barrier *)NULL)) { \
332
HANDLE_ERROR_FUNC_WITH_CODE(ABT_ERR_INV_BARRIER); \
333
return ABT_ERR_INV_BARRIER; \
334
} \
335
} while (0)
336
337
#define ABTI_CHECK_NULL_XSTREAM_BARRIER_PTR(p) \
338
do { \
339
if (ABTI_IS_ERROR_CHECK_ENABLED && \
340
ABTU_unlikely(p == (ABTI_xstream_barrier *)NULL)) { \
341
HANDLE_ERROR_FUNC_WITH_CODE(ABT_ERR_INV_XSTREAM_BARRIER); \
342
return ABT_ERR_INV_XSTREAM_BARRIER; \
343
} \
344
} while (0)
345
346
#define ABTI_CHECK_NULL_TIMER_PTR(p) \
347
do { \
348
if (ABTI_IS_ERROR_CHECK_ENABLED && \
349
ABTU_unlikely(p == (ABTI_timer *)NULL)) { \
350
HANDLE_ERROR_FUNC_WITH_CODE(ABT_ERR_INV_TIMER); \
351
return ABT_ERR_INV_TIMER; \
352
} \
353
} while (0)
354
355
#define ABTI_CHECK_NULL_TOOL_CONTEXT_PTR(p) \
356
do { \
357
if (ABTI_IS_ERROR_CHECK_ENABLED && \
358
ABTU_unlikely(p == (ABTI_tool_context *)NULL)) { \
359
HANDLE_ERROR_FUNC_WITH_CODE(ABT_ERR_INV_TOOL_CONTEXT); \
360
return ABT_ERR_INV_TOOL_CONTEXT; \
361
} \
362
} while (0)
363
364
#endif
/* ABTI_ERROR_H_INCLUDED */
abt_config.h
Generated on Fri Jan 28 2022 04:21:57 for ARGOBOTS by
1.8.17