Xenomai  3.0.5
ancillaries.h
1 /*
2  * Copyright (C) 2013 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_ANCILLARIES_H
19 #define _BOILERPLATE_ANCILLARIES_H
20 
21 #include <stdarg.h>
22 #include <time.h>
23 #include <pthread.h>
24 #include <sched.h>
25 #include <string.h>
26 #include <boilerplate/signal.h>
27 #include <boilerplate/compiler.h>
28 #include <boilerplate/atomic.h>
29 
30 extern pthread_mutex_t __printlock;
31 
32 struct error_frame;
33 struct cleanup_block;
34 
35 struct name_generator {
36  const char *radix;
37  int length;
38  atomic_t serial;
39 };
40 
41 #define DEFINE_NAME_GENERATOR(__name, __radix, __type, __member) \
42  struct name_generator __name = { \
43  .radix = __radix, \
44  .length = sizeof ((__type *)0)->__member, \
45  .serial = ATOMIC_INIT(0), \
46  }
47 
48 #define ONE_BILLION 1000000000
49 
50 void __namecpy_requires_character_array_as_destination(void);
51 
52 #define namecpy(__dst, __src) \
53  ({ \
54  if (!__builtin_types_compatible_p(typeof(__dst), char[])) \
55  __namecpy_requires_character_array_as_destination(); \
56  strncpy((__dst), __src, sizeof(__dst) - 1); \
57  __dst[sizeof(__dst) - 1] = '\0'; \
58  __dst; \
59  })
60 
61 #define early_panic(__fmt, __args...) \
62  __early_panic(__func__, __fmt, ##__args)
63 
64 #define panic(__fmt, __args...) \
65  __panic(__func__, __fmt, ##__args)
66 
67 #ifdef __cplusplus
68 extern "C" {
69 #endif
70 
71 void __run_cleanup_block(struct cleanup_block *cb);
72 
73 void __printout(const char *name,
74  const char *header,
75  const char *fmt, va_list ap);
76 
77 void __noreturn __early_panic(const char *fn,
78  const char *fmt, ...);
79 
80 void __noreturn ___panic(const char *fn,
81  const char *name,
82  const char *fmt, va_list ap);
83 
84 void __noreturn __panic(const char *fn,
85  const char *fmt, ...);
86 
87 void __warning(const char *name,
88  const char *fmt, va_list ap);
89 
90 void early_warning(const char *fmt, ...);
91 
92 void warning(const char *fmt, ...);
93 
94 void __notice(const char *name,
95  const char *fmt, va_list ap);
96 
97 void early_notice(const char *fmt, ...);
98 
99 void notice(const char *fmt, ...);
100 
101 void __boilerplate_init(void);
102 
103 const char *symerror(int errnum);
104 
105 char *generate_name(char *buf, const char *radix,
106  struct name_generator *ngen);
107 
108 void error_hook(struct error_frame *ef);
109 
110 int get_static_cpu_count(void);
111 
112 int get_online_cpu_set(cpu_set_t *cpuset);
113 
114 int get_realtime_cpu_set(cpu_set_t *cpuset);
115 
116 int get_current_cpu(void);
117 
118 pid_t get_thread_pid(void);
119 
120 char *lookup_command(const char *cmd);
121 
122 size_t get_mem_size(const char *arg);
123 
124 #ifdef __cplusplus
125 }
126 #endif
127 
128 extern const char *config_strings[];
129 
130 #endif /* _BOILERPLATE_ANCILLARIES_H */
Copyright © 2011 Gilles Chanteperdrix gilles.chanteperdrix@xenomai.org.
Definition: atomic.h:24