Xenomai  3.1
tunables.h
1 /*
2  * Copyright (C) 2015 Philippe Gerum <rpm@xenomai.org>.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13 
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  */
18 #ifndef _BOILERPLATE_TUNABLES_H
19 #define _BOILERPLATE_TUNABLES_H
20 
21 #include <assert.h>
22 #include <boilerplate/setup.h>
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 static inline int __may_change_config_tunable(void)
29 {
30  return !__config_done;
31 }
32 
33 #define __tunable_set_call(__name, __scope) \
34  __assign_ ## __name ## _ ## __scope
35 
36 #define __tunable_get_call(__name, __scope) \
37  __read_ ## __name ## _ ## __scope
38 
39 #define __define_tunable(__name, __type, __val, __scope) \
40  void __tunable_set_call(__name, __scope)(__typeof__(__type) __val)
41 
42 #define __read_tunable(__name, __type, __scope) \
43  __typeof__(__type) __tunable_get_call(__name, __scope)(void)
44 
45 #define define_config_tunable(__name, __type, __val) \
46  __define_tunable(__name, __type, __val, config)
47 
48 #define define_runtime_tunable(__name, __type, __val) \
49  __define_tunable(__name, __type, __val, runtime)
50 
51 #define read_config_tunable(__name, __type) \
52  __read_tunable(__name, __type, config)
53 
54 #define read_runtime_tunable(__name, __type) \
55  __read_tunable(__name, __type, runtime)
56 
57 #define set_config_tunable(__name, __val) \
58  do { \
59  assert(__may_change_config_tunable()); \
60  __tunable_set_call(__name, config)(__val); \
61  } while (0)
62 
63 #define get_config_tunable(__name) \
64  __tunable_get_call(__name, config)()
65 
66 #define set_runtime_tunable(__name, __val) \
67  __tunable_set_call(__name, runtime)(__val)
68 
69 #define get_runtime_tunable(__name) \
70  __tunable_get_call(__name, runtime)()
71 
72 static inline define_config_tunable(cpu_affinity, cpu_set_t, cpus)
73 {
74  __base_setup_data.cpu_affinity = cpus;
75 }
76 
77 static inline read_config_tunable(cpu_affinity, cpu_set_t)
78 {
79  return __base_setup_data.cpu_affinity;
80 }
81 
82 static inline define_config_tunable(no_mlock, int, nolock)
83 {
84  __base_setup_data.no_mlock = nolock;
85 }
86 
87 static inline read_config_tunable(no_mlock, int)
88 {
89  return __base_setup_data.no_mlock;
90 }
91 
92 static inline define_config_tunable(no_sanity, int, nosanity)
93 {
94  __base_setup_data.no_sanity = nosanity;
95 }
96 
97 static inline read_config_tunable(no_sanity, int)
98 {
99  return __base_setup_data.no_sanity;
100 }
101 
102 static inline define_runtime_tunable(verbosity_level, int, level)
103 {
104  __base_setup_data.verbosity_level = level;
105 }
106 
107 static inline read_runtime_tunable(verbosity_level, int)
108 {
109  return __base_setup_data.verbosity_level;
110 }
111 
112 static inline define_runtime_tunable(trace_level, int, level)
113 {
114  __base_setup_data.trace_level = level;
115 }
116 
117 static inline read_runtime_tunable(trace_level, int)
118 {
119  return __base_setup_data.trace_level;
120 }
121 
122 #ifdef __cplusplus
123 }
124 #endif
125 
126 #endif /* !_BOILERPLATE_TUNABLES_H */