Xenomai  3.0-rc3
cobalt.h
1 /*
2  * Copyright (C) 2014 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 _COBALT_SYS_COBALT_H
19 #define _COBALT_SYS_COBALT_H
20 
21 #include <sys/types.h>
22 #include <signal.h>
23 #include <pthread.h>
24 #include <sched.h>
25 #include <semaphore.h>
26 #include <errno.h>
27 #include <stdio.h>
28 #include <time.h>
29 #include <boilerplate/atomic.h>
30 #include <boilerplate/list.h>
31 #include <cobalt/uapi/kernel/synch.h>
32 #include <cobalt/uapi/kernel/vdso.h>
33 #include <cobalt/uapi/corectl.h>
34 #include <cobalt/uapi/mutex.h>
35 #include <cobalt/uapi/event.h>
36 #include <cobalt/uapi/monitor.h>
37 #include <cobalt/uapi/thread.h>
38 #include <cobalt/uapi/cond.h>
39 #include <cobalt/uapi/sem.h>
40 
41 #define report_error(fmt, args...) \
42  __STD(fprintf(stderr, "Xenomai/cobalt: %s(): " fmt "\n", __func__, ##args))
43 
44 #define report_error_cont(fmt, args...) \
45  __STD(fprintf(stderr, " " fmt "\n", ##args))
46 
47 #define cobalt_commit_memory(p) __cobalt_commit_memory(p, sizeof(*p))
48 
49 struct cobalt_tsd_hook {
50  void (*create_tsd)(void);
51  void (*delete_tsd)(void);
52  struct pvholder next;
53 };
54 
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58 
59 int cobalt_extend(unsigned int magic);
60 
61 int cobalt_corectl(int request, void *buf, size_t bufsz);
62 
63 int cobalt_thread_stat(pid_t pid,
64  struct cobalt_threadstat *stat);
65 
66 int cobalt_serial_debug(const char *fmt, ...);
67 
68 size_t cobalt_get_stacksize(size_t size);
69 
70 void __cobalt_commit_memory(void *p, size_t len);
71 
72 void cobalt_thread_harden(void);
73 
74 void cobalt_thread_relax(void);
75 
76 int cobalt_thread_join(pthread_t thread);
77 
78 pid_t cobalt_thread_pid(pthread_t thread);
79 
80 int cobalt_monitor_init(cobalt_monitor_t *mon,
81  clockid_t clk_id, int flags);
82 
83 int cobalt_monitor_destroy(cobalt_monitor_t *mon);
84 
85 int cobalt_monitor_enter(cobalt_monitor_t *mon);
86 
87 int cobalt_monitor_exit(cobalt_monitor_t *mon);
88 
89 int cobalt_monitor_wait(cobalt_monitor_t *mon, int event,
90  const struct timespec *ts);
91 
92 void cobalt_monitor_grant(cobalt_monitor_t *mon,
93  struct xnthread_user_window *u_window);
94 
95 int cobalt_monitor_grant_sync(cobalt_monitor_t *mon,
96  struct xnthread_user_window *u_window);
97 
98 void cobalt_monitor_grant_all(cobalt_monitor_t *mon);
99 
100 int cobalt_monitor_grant_all_sync(cobalt_monitor_t *mon);
101 
102 void cobalt_monitor_drain(cobalt_monitor_t *mon);
103 
104 int cobalt_monitor_drain_sync(cobalt_monitor_t *mon);
105 
106 void cobalt_monitor_drain_all(cobalt_monitor_t *mon);
107 
108 int cobalt_monitor_drain_all_sync(cobalt_monitor_t *mon);
109 
110 int cobalt_event_init(cobalt_event_t *event,
111  unsigned int value,
112  int flags);
113 
114 int cobalt_event_post(cobalt_event_t *event,
115  unsigned int bits);
116 
117 int cobalt_event_wait(cobalt_event_t *event,
118  unsigned int bits,
119  unsigned int *bits_r,
120  int mode,
121  const struct timespec *timeout);
122 
123 unsigned long cobalt_event_clear(cobalt_event_t *event,
124  unsigned int bits);
125 
126 int cobalt_event_inquire(cobalt_event_t *event,
127  struct cobalt_event_info *info,
128  pid_t *waitlist, size_t waitsz);
129 
130 int cobalt_event_destroy(cobalt_event_t *event);
131 
132 int cobalt_sem_inquire(sem_t *sem, struct cobalt_sem_info *info,
133  pid_t *waitlist, size_t waitsz);
134 
135 int cobalt_sched_weighted_prio(int policy,
136  const struct sched_param_ex *param_ex);
137 
138 void cobalt_register_tsd_hook(struct cobalt_tsd_hook *th);
139 
140 void __libcobalt_init(void);
141 
142 extern int __cobalt_defer_init;
143 
144 extern int __cobalt_no_shadow;
145 
146 extern int __cobalt_control_bind;
147 
148 extern int __cobalt_main_prio;
149 
150 extern int __cobalt_print_bufsz;
151 
152 #ifdef __cplusplus
153 }
154 #endif
155 
156 #endif /* !_COBALT_SYS_COBALT_H */