Add `urcu_posix_assert()` as `assert()` replacement
[urcu.git] / include / urcu / assert.h
1 #ifndef _URCU_ASSERT_H
2 #define _URCU_ASSERT_H
3
4 /*
5 * urcu/assert.h
6 *
7 * Userspace RCU assertion facilities.
8 *
9 * Copyright (c) 2021 Francis Deslauriers <francis.deslauriers@efficios.com>
10 *
11 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights
14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 * copies of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
17 *
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
20 */
21
22 #include <urcu/config.h>
23
24 /*
25 * Force usage of an expression to prevent unused expression compiler warning.
26 */
27 #define _urcu_use_expression(_expr) ((void) sizeof((void) (_expr), 0))
28
29 #ifdef NDEBUG
30 /*
31 * Vanilla assert() replacement. When NDEBUG is defined, the expression is
32 * consumed to prevent unused variable compile warnings.
33 */
34 # define urcu_posix_assert(_cond) _urcu_use_expression(_cond)
35 #else
36 # include <assert.h>
37 # define urcu_posix_assert(_cond) assert(_cond)
38 #endif
39
40 #if defined(DEBUG_RCU) || defined(CONFIG_RCU_DEBUG)
41
42 /*
43 * Enables debugging/expensive assertions to be used in fast paths and only
44 * enabled on demand. When disabled, the expression is consumed to prevent
45 * unused variable compile warnings.
46 */
47 # define urcu_assert_debug(_cond) urcu_posix_assert(_cond)
48 #else
49 # define urcu_assert_debug(_cond) _urcu_use_expression(_cond)
50 #endif
51
52 #endif /* _URCU_ASSERT_H */
This page took 0.029272 seconds and 4 git commands to generate.