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