Xenomai  3.0.8
assert.h
1 /*
2  * Copyright (C) 2006 Philippe Gerum <rpm@xenomai.org>.
3  *
4  * Xenomai is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published
6  * by the Free Software Foundation; either version 2 of the License,
7  * or (at your option) any later version.
8  *
9  * Xenomai is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with Xenomai; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
17  * 02111-1307, USA.
18  */
19 #ifndef _COBALT_KERNEL_ASSERT_H
20 #define _COBALT_KERNEL_ASSERT_H
21 
22 #include <linux/kconfig.h>
23 #include <cobalt/kernel/trace.h>
24 #include <cobalt/kernel/ancillaries.h>
25 
26 #define XENO_INFO KERN_INFO "[Xenomai] "
27 #define XENO_WARNING KERN_WARNING "[Xenomai] "
28 #define XENO_ERR KERN_ERR "[Xenomai] "
29 
30 #define XENO_DEBUG(__subsys) \
31  IS_ENABLED(CONFIG_XENO_OPT_DEBUG_##__subsys)
32 #define XENO_ASSERT(__subsys, __cond) \
33  (!WARN_ON(XENO_DEBUG(__subsys) && !(__cond)))
34 #define XENO_BUG(__subsys) \
35  BUG_ON(XENO_DEBUG(__subsys))
36 #define XENO_BUG_ON(__subsys, __cond) \
37  BUG_ON(XENO_DEBUG(__subsys) && (__cond))
38 #define XENO_WARN(__subsys, __cond, __fmt...) \
39  WARN(XENO_DEBUG(__subsys) && (__cond), __fmt)
40 #define XENO_WARN_ON(__subsys, __cond) \
41  WARN_ON(XENO_DEBUG(__subsys) && (__cond))
42 #define XENO_WARN_ON_ONCE(__subsys, __cond) \
43  WARN_ON_ONCE(XENO_DEBUG(__subsys) && (__cond))
44 #ifdef CONFIG_SMP
45 #define XENO_BUG_ON_SMP(__subsys, __cond) \
46  XENO_BUG_ON(__subsys, __cond)
47 #define XENO_WARN_ON_SMP(__subsys, __cond) \
48  XENO_WARN_ON(__subsys, __cond)
49 #define XENO_WARN_ON_ONCE_SMP(__subsys, __cond) \
50  XENO_WARN_ON_ONCE(__subsys, __cond)
51 #else
52 #define XENO_BUG_ON_SMP(__subsys, __cond) \
53  do { } while (0)
54 #define XENO_WARN_ON_SMP(__subsys, __cond) \
55  do { } while (0)
56 #define XENO_WARN_ON_ONCE_SMP(__subsys, __cond) \
57  do { } while (0)
58 #endif
59 
60 #define primary_mode_only() XENO_BUG_ON(CONTEXT, ipipe_root_p)
61 #define secondary_mode_only() XENO_BUG_ON(CONTEXT, !ipipe_root_p)
62 #define interrupt_only() XENO_BUG_ON(CONTEXT, !xnsched_interrupt_p())
63 #define realtime_cpu_only() XENO_BUG_ON(CONTEXT, !xnsched_supported_cpu(ipipe_processor_id()))
64 #define thread_only() XENO_BUG_ON(CONTEXT, xnsched_interrupt_p())
65 #define irqoff_only() XENO_BUG_ON(CONTEXT, hard_irqs_disabled() == 0)
66 #ifdef CONFIG_XENO_OPT_DEBUG_LOCKING
67 #define atomic_only() XENO_BUG_ON(CONTEXT, (xnlock_is_owner(&nklock) && hard_irqs_disabled()) == 0)
68 #define preemptible_only() XENO_BUG_ON(CONTEXT, xnlock_is_owner(&nklock) || hard_irqs_disabled())
69 #else
70 #define atomic_only() XENO_BUG_ON(CONTEXT, hard_irqs_disabled() == 0)
71 #define preemptible_only() XENO_BUG_ON(CONTEXT, hard_irqs_disabled() != 0)
72 #endif
73 
74 #endif /* !_COBALT_KERNEL_ASSERT_H */