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