Xenomai  3.1
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 
27 struct error_frame;
28 
29 #define ONE_BILLION 1000000000
30 
31 void __namecpy_requires_character_array_as_destination(void);
32 
33 #define namecpy(__dst, __src) \
34  ({ \
35  if (!__builtin_types_compatible_p(typeof(__dst), char[])) \
36  __namecpy_requires_character_array_as_destination(); \
37  strncpy((__dst), __src, sizeof(__dst)); \
38  __dst[sizeof(__dst) - 1] = '\0'; \
39  __dst; \
40  })
41 
42 #define early_panic(__fmt, __args...) \
43  __early_panic(__func__, __fmt, ##__args)
44 
45 #define panic(__fmt, __args...) \
46  __panic(__func__, __fmt, ##__args)
47 
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51 
52 void __printout(const char *name,
53  const char *header,
54  const char *fmt, va_list ap);
55 
56 void __noreturn __early_panic(const char *fn,
57  const char *fmt, ...);
58 
59 void __noreturn ___panic(const char *fn,
60  const char *name,
61  const char *fmt, va_list ap);
62 
63 void __noreturn __panic(const char *fn,
64  const char *fmt, ...);
65 
66 void __warning(const char *name,
67  const char *fmt, va_list ap);
68 
69 void early_warning(const char *fmt, ...);
70 
71 void warning(const char *fmt, ...);
72 
73 void __notice(const char *name,
74  const char *fmt, va_list ap);
75 
76 void early_notice(const char *fmt, ...);
77 
78 void notice(const char *fmt, ...);
79 
80 void __boilerplate_init(void);
81 
82 const char *symerror(int errnum);
83 
84 void error_hook(struct error_frame *ef);
85 
86 int get_static_cpu_count(void);
87 
88 int get_online_cpu_set(cpu_set_t *cpuset);
89 
90 int get_realtime_cpu_set(cpu_set_t *cpuset);
91 
92 int get_current_cpu(void);
93 
94 pid_t get_thread_pid(void);
95 
96 char *lookup_command(const char *cmd);
97 
98 size_t get_mem_size(const char *arg);
99 
100 extern const char *config_strings[];
101 
102 extern pthread_mutex_t __printlock;
103 
104 #ifdef __cplusplus
105 }
106 #endif
107 
108 #endif /* _BOILERPLATE_ANCILLARIES_H */