]> rtime.felk.cvut.cz Git - frescor/fosa.git/blob - include/fosa_opaque_types.h
FOSA-PaRTiKle: changes in allocated signals for longjumps
[frescor/fosa.git] / include / fosa_opaque_types.h
1 //----------------------------------------------------------------------
2 //  Copyright (C) 2006 - 2007 by the FRESCOR consortium:
3 //
4 //    Universidad de Cantabria,              SPAIN
5 //    University of York,                    UK
6 //    Scuola Superiore Sant'Anna,            ITALY
7 //    Kaiserslautern University,             GERMANY
8 //    Univ. Politecnica  Valencia,           SPAIN
9 //    Czech Technical University in Prague,  CZECH REPUBLIC
10 //    ENEA                                   SWEDEN
11 //    Thales Communication S.A.              FRANCE
12 //    Visual Tools S.A.                      SPAIN
13 //    Rapita Systems Ltd                     UK
14 //    Evidence                               ITALY
15 //
16 //    See http://www.frescor.org
17 //
18 //        The FRESCOR project (FP6/2005/IST/5-034026) is funded
19 //        in part by the European Union Sixth Framework Programme
20 //        The European Union is not liable of any use that may be
21 //        made of this code.
22 //
23 //
24 //  based on previous work (FSF) done in the FIRST project
25 //
26 //   Copyright (C) 2005  Mälardalen University, SWEDEN
27 //                       Scuola Superiore S.Anna, ITALY
28 //                       Universidad de Cantabria, SPAIN
29 //                       University of York, UK
30 //
31 // This file is part of FOSA (Frsh Operating System Abstraction)
32 //
33 // FOSA is free software; you can redistribute it and/or modify it
34 // under terms of the GNU General Public License as published by the
35 // Free Software Foundation; either version 2, or (at your option) any
36 // later version.  FOSA is distributed in the hope that it will be
37 // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
38 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
39 // General Public License for more details. You should have received a
40 // copy of the GNU General Public License along with FOSA; see file
41 // COPYING. If not, write to the Free Software Foundation, 675 Mass Ave,
42 // Cambridge, MA 02139, USA.
43 //
44 // As a special exception, including FOSA header files in a file,
45 // instantiating FOSA generics or templates, or linking other files
46 // with FOSA objects to produce an executable application, does not
47 // by itself cause the resulting executable application to be covered
48 // by the GNU General Public License. This exception does not
49 // however invalidate any other reasons why the executable file might be
50 // covered by the GNU Public License.
51 // -----------------------------------------------------------------------
52 //fosa_opaque_types.h
53 //==============================================
54 //  ********  ******    ********  **********
55 //  **///// /**    **  **//////  /**     /**
56 //  **      /**    ** /**        /**     /**
57 //  ******* /**    ** /********* /**********
58 //  **////  /**    ** ////////** /**//////**
59 //  **      /**    **        /** /**     /**
60 //  **      /**    **  ********  /**     /**
61 //  //       /******/  ////////   //      //
62 //
63 // FOSA(Frescor Operating System Adaptation layer)
64 //================================================
65
66 // Implementation dependent definitions
67
68 #ifndef _FOSA_OPAQUE_TYPES_H_
69 #define _FOSA_OPAQUE_TYPES_H_
70
71 #include <stdbool.h>
72
73 #include "fosa_cpp_macros.h"
74
75 ///////////////////////  MARTE_OS /////////////////////////////
76
77 #ifdef MARTE_OS
78
79 #include <pthread.h>
80 #include <signal.h>
81 #include <time.h>
82 #include <sched.h>
83 #include <errno.h>
84
85 FOSA_CPP_BEGIN_DECLS
86
87 /* Time */
88 /********/
89 // typedef struct timespec fosa_rel_time_t;
90 // typedef struct timespec fosa_abs_time_t;
91
92 /* Thread and signals */
93 /**********************/
94 typedef pthread_t FOSA_THREAD_ID_T_OPAQUE;
95 typedef pthread_attr_t FOSA_THREAD_ATTR_T_OPAQUE;
96
97 typedef int FOSA_SIGNAL_T_OPAQUE;
98 /* Signal info is defined as a union in thread_and_signals */
99
100 #define FOSA_SIGNAL_MIN       SIGRTMIN
101 #define FOSA_SIGNAL_MAX       SIGRTMIN+0
102
103 #define FOSA_NULL_SIGNAL 0
104
105 /* Clocks and timers */
106 /**********************/
107 typedef clockid_t FOSA_CLOCK_ID_T_OPAQUE;
108 typedef timer_t FOSA_TIMER_ID_T_OPAQUE;
109
110 #define FOSA_SYSTEM_CLOCK_OPAQUE  CLOCK_MONOTONIC
111
112 /* Mutex and conditional variables */
113 /***********************************/
114 typedef pthread_mutex_t FOSA_MUTEX_T_OPAQUE;
115 typedef pthread_cond_t FOSA_COND_T_OPAQUE;
116
117
118 /* Application defined Scheduling */
119 /**********************************/
120 typedef struct {
121     posix_appsched_actions_t actions;
122     struct timespec *timeout_ptr;
123     struct timespec timeout;
124     bool rejected;
125     bool suspended;
126     bool activated;
127 } fosa_ads_actions_internal_t;
128
129 #define FOSA_ADS_ACTIONS_T_OPAQUE fosa_ads_actions_internal_t
130
131 /* Local jump */
132 /**************/
133 #include "marte_non_local_jmp.h"
134
135 #define FOSA_LONG_JUMP_CONTEXT_T_OPAQUE  struct { \
136   marte_nonlocaljmp_context_t marte_context;      \
137   fosa_thread_id_t tid;                            \
138 }
139
140
141 /* FOSA errors */
142 /***************/
143 /** Not enough memory available **/
144 #define FOSA_ENOMEM   ENOMEM
145
146 /** Invalid parameter **/
147 #define FOSA_EINVAL   EINVAL
148
149 /** Still pending information **/
150 #define FOSA_EAGAIN   EAGAIN
151
152 /** FOSA ADS errors **/
153 #ifdef MARTE_OS
154 #define EREJECT   201 /* (for linux_lib_arch) Appsched has rejected object */
155 #endif
156
157 #define FOSA_EREJECT   EREJECT
158 #define FOSA_EMASKED   -2
159 #define FOSA_EPOLICY   -3
160
161 #define FOSA_ETIMEDOUT ETIMEDOUT
162
163 #endif
164
165 ///////////////////////  End of MARTE_OS  /////////////////////////////
166
167
168 /////////////////////// RT_LINUX ///////////////////////////
169
170 #ifdef RT_LINUX
171
172 /* Very similar to MARTE_OS but I leave separate for clarity */
173
174 #include <pthread.h>
175 #include <signal.h>
176 #include <time.h>
177 #include <sched.h>
178 #include <errno.h>
179 #include <rtl_timer.h>
180
181 /* Time */
182 /********/
183 // typedef struct timespec fosa_rel_time_t;
184 // typedef struct timespec fosa_abs_time_t;
185
186
187 /* Threads and signals */
188 /***********************/
189 #define    FOSA_THREAD_ID_T_OPAQUE pthread_t
190
191 typedef pthread_attr_t FOSA_THREAD_ATTR_T_OPAQUE;
192 typedef int FOSA_SIGNAL_T_OPAQUE;
193 /* Signal info is defined as a union in fosa_types.h */
194
195 // The minimum and maximum signal numbers that may be used by the FRSH
196 // implementation
197 #define FOSA_SIGNAL_MIN       SIGRTMIN
198 #define FOSA_SIGNAL_MAX       SIGRTMIN+0
199 #define FOSA_NULL_SIGNAL 0
200
201 /* Clocks and timers */
202 /*********************/
203 #define    FOSA_CLOCK_ID_T_OPAQUE    clockid_t
204 #define    FOSA_TIMER_ID_T_OPAQUE    timer_t
205 #define    FOSA_SYSTEM_CLOCK_OPAQUE  CLOCK_MONOTONIC
206
207 /* Mutex and cond vars */
208 /***********************/
209 typedef pthread_mutex_t FOSA_MUTEX_T_OPAQUE;
210 #define    FOSA_COND_T_OPAQUE        pthread_cond_t
211
212
213 /* FOSA Errors */
214 /***************/
215 /** Not enough memory available **/
216 #define FOSA_ENOMEM   ENOMEM
217 /** Invalid parameter **/
218 #define FOSA_EINVAL   EINVAL
219 /** Still pending information **/
220 #define FOSA_EAGAIN   EAGAIN
221
222 /** FOSA ADS errors **/
223 #define FOSA_EREJECT   EREJECT
224 #define FOSA_EMASKED   -2
225 #define FOSA_EPOLICY   -3
226
227 #define FOSA_ETIMEDOUT ETIMEDOUT
228
229 #endif
230
231 ///////////////////////  End of RT_LINUX  /////////////////////////////
232
233
234 ////////////////////////// OSE    //////////////////////////////////////
235
236 #ifdef OSE
237
238 /* Time */
239 /********/
240 // typedef struct timespec fosa_rel_time_t;
241 // typedef struct timespec fosa_abs_time_t;
242
243
244 /* Put OSE dependent includes and defines here */
245
246 #endif /* OSE */
247
248
249
250 /////////////////////// AQuoSA ///////////////////////////
251
252 #ifdef AQuoSA
253
254 #define __USE_UNIX98
255
256 #include <pthread.h>
257 #include <signal.h>
258 #include <errno.h>
259 #include <time.h>
260
261 /* Time */
262 /********/
263 // typedef struct timespec fosa_rel_time_t;
264 // typedef struct timespec fosa_abs_time_t;
265
266
267 /* Threads and signals */
268 /***********************/
269 typedef struct {
270         pthread_t pthread_id;
271         pid_t linux_pid;
272         pid_t linux_tid;
273 } FOSA_THREAD_ID_T_OPAQUE;
274
275
276 typedef pthread_attr_t FOSA_THREAD_ATTR_T_OPAQUE;
277 typedef int FOSA_SIGNAL_T_OPAQUE;
278
279
280 // The minimum and maximum signal numbers that may be used by the FRSH
281 // implementation
282 #define FOSA_SIGNAL_MIN       SIGRTMIN
283 #define FOSA_SIGNAL_MAX       SIGRTMIN+0
284
285 #define FOSA_NULL_SIGNAL 0
286
287
288 /* Clocks and signals */
289 /**********************/
290 #define    FOSA_CLOCK_ID_T_OPAQUE    clockid_t
291 #define    FOSA_SYSTEM_CLOCK_OPAQUE  CLOCK_MONOTONIC
292 #define    FOSA_TIMER_ID_T_OPAQUE    timer_t
293
294
295
296 /* Mutex and cond vars */
297 /***********************/
298 typedef pthread_mutex_t FOSA_MUTEX_T_OPAQUE;
299 #define    FOSA_COND_T_OPAQUE        pthread_cond_t
300
301
302 /* Application Defined Scheduling */
303 /**********************************/
304 /* hack to get AQuoSA sources compile without having none
305  * of the application level scheduler header files and symbols */
306 #define posix_appsched_actions_t int
307 #define FOSA_LONG_JUMP_CONTEXT_T_OPAQUE int
308
309 #define FOSA_ADS_ACTIONS_T_OPAQUE posix_appsched_actions_t
310
311
312 /* FOSA Errors */
313
314 /** Not enough memory available **/
315 #define FOSA_ENOMEM   ENOMEM
316
317 /** Invalid parameter **/
318 #define FOSA_EINVAL   EINVAL
319
320 /** Still pending information **/
321 #define FOSA_EAGAIN   EAGAIN
322
323 #define FOSA_EREJECT   EREJECT
324 #define FOSA_EMASKED   -2
325 #define FOSA_EPOLICY   -3
326
327 #define FOSA_ETIMEDOUT ETIMEDOUT
328
329
330 #endif 
331 ////////////////// END of AQuoSA //////////////////////
332
333
334
335 /////////////////////////////////// PARTIKLE ///////////////////////////////////////////
336 #if defined(PARTIKLE)
337
338 #include <pthread.h>
339 #include <signal.h>
340 #include <time.h>
341 #include <sched.h>
342 #include <stdlib.h>
343 #include <setjmp.h>
344
345 typedef struct {
346     posix_appsched_actions_t actions;
347     struct timespec * timeout_ptr;
348     struct timespec timeout;
349     bool rejected;
350     bool suspended;
351     bool activated;
352 } FOSA_ADS_ACTIONS_T_OPAQUE;
353
354 typedef struct {
355   jmp_buf jmp_context;
356   bool jmp_hasexecuted;
357   sigset_t jmp_sigmask;
358 } FOSA_LONG_JUMP_CONTEXT_T_OPAQUE;
359
360 typedef pthread_t                   FOSA_THREAD_ID_T_OPAQUE;
361 typedef pthread_attr_t              FOSA_THREAD_ATTR_T_OPAQUE;
362 typedef int                         FOSA_SIGNAL_T_OPAQUE;
363 typedef clockid_t                   FOSA_CLOCK_ID_T_OPAQUE;
364 typedef timer_t                     FOSA_TIMER_ID_T_OPAQUE;
365 typedef pthread_cond_t              FOSA_COND_T_OPAQUE;
366 typedef pthread_mutex_t             FOSA_MUTEX_T_OPAQUE;
367
368
369
370 enum _fosa_clocks_e {
371   FOSA_SYSTEM_CLOCK_OPAQUE = CLOCK_MONOTONIC
372 };
373
374 enum _fosa_signal_limits_e {
375   LONGJMP_NSIG = 3,
376   LONGJMP_FIRSTSIG = SIGRTMAX - LONGJMP_NSIG + 1,
377   FOSA_SIGNAL_MAX = LONGJMP_FIRSTSIG - 1,
378   FOSA_SIGNAL_MIN = FOSA_SIGNAL_MAX,
379 };
380
381 enum _fosa_errors_e {
382   FOSA_EINVAL = EINVAL,
383   FOSA_EAGAIN = EAGAIN,
384   FOSA_EREJECT = EREJECT,
385   FOSA_EMASKED = EMASKED,
386   FOSA_EPOLICY = EPOLICY, 
387   FOSA_ETIMEDOUT = ETIMEDOUT,
388   FOSA_ENOMEM = ENOMEM,
389 };
390
391 #endif
392 /////////////////////////////////// PARTIKLE  END //////////////////////////////////////
393
394
395
396 ////////////////////////// VIRTUAL TIME    //////////////////////////////////////
397 #ifdef VIRTUAL_TIME
398
399 /* Time */
400 /********/
401 // typedef struct timespec fosa_rel_time_t;
402 // typedef struct timespec fosa_abs_time_t;
403
404 #include <fosa_vt.h>
405
406 #define FOSA_THREAD_ID_T_OPAQUE   vt_posix_process_t
407 #define FOSA_THREAD_ATTR_T_OPAQUE fosa_thread_attr_t
408 #define FOSA_SIGNAL_T_OPAQUE      int
409
410 #define FOSA_MUTEX_T_OPAQUE fosa_mutex_t
411
412 // The minimum and maximum signal numbers that may be used by the FRSH
413 // implementation
414 #define FOSA_SIGNAL_MIN       8
415 #define FOSA_SIGNAL_MAX       31
416
417 // the min. and max. priority a fosa thread can have
418 #define FOSA_PRIORITY_MAX VT_PRIORITY_MIN - 1
419 #define FOSA_PRIORITY_MIN VT_PRIORITY_MAX
420
421 #define FOSA_NULL_SIGNAL        0
422
423 /* FOSA Errors and return values*/
424
425 /** Invalid parameter **/
426 #define FOSA_EINVAL   -1
427
428 /** Not enough memory available **/
429 #define FOSA_ENOMEM   -2
430
431 /** Still pending information **/
432 #define FOSA_EAGAIN   -3
433
434 /** Mutex not available **/
435 #define FOSA_EBUSY         -4
436
437 /** Cond var timedout **/
438 #define FOSA_ETIMEDOUT  -5
439
440 /** FOSA ADS errors **/
441 #define FOSA_EREJECT   -6
442 #define FOSA_EMASKED   -7
443
444
445 /** Sched policy not correct */
446 #define FOSA_EPOLICY    -8
447
448 /** the value given by thread_id is not valid for ADS */
449 #define FOSA_ESRCH              -9
450
451 /** retval if no action performed **/
452 #define FOSA_NO_ACTION  0
453
454 #endif /* VIRTUAL_TIME */
455 //////////////////////////End of VIRTUAL TIME ///////////////////////////////////
456
457
458 ////////////////////////// DUMMY_OS    //////////////////////////////////////
459
460 #if defined(DUMMY_OS)
461
462 /* With this define we make sure that we are truly POSIX and OSE */
463 /* independent at the FRSH code.                                 */
464 /*****************************************************************/
465
466 /* Time */
467 /********/
468 // typedef struct timespec fosa_rel_time_t;
469 // typedef struct timespec fosa_abs_time_t;
470
471 /* Thread and signals */
472 /**********************/
473 typedef int FOSA_THREAD_ID_T_OPAQUE;
474 typedef int FOSA_THREAD_ATTR_T_OPAQUE;
475
476 typedef int FOSA_SIGNAL_T_OPAQUE;
477 typedef int FOSA_SIGNAL_INFO_T_OPAQUE;
478
479 /* Signal info is defined as a union in thread_and_signals */
480
481 #define FOSA_SIGNAL_MIN     42
482 #define FOSA_SIGNAL_MAX     44
483
484 #define FOSA_NULL_SIGNAL 0
485
486 /* Clocks and timers */
487 /**********************/
488 typedef int FOSA_CLOCK_ID_T_OPAQUE;
489 typedef int FOSA_TIMER_ID_T_OPAQUE;
490
491 #define FOSA_SYSTEM_CLOCK_OPAQUE  25
492
493 /* Mutex and conditional variables */
494 /***********************************/
495 typedef int FOSA_MUTEX_T_OPAQUE;
496 typedef int FOSA_COND_T_OPAQUE;
497
498 /* Application defined Scheduling */
499 /**********************************/
500 #define FOSA_ADS_ACTIONS_T_OPAQUE  int
501
502
503 #endif /* DUMMY */
504 //////////////////////////End of DUMMY_OS ////////////////////////////////////
505
506 FOSA_CPP_END_DECLS
507
508
509 #endif // _FOSA_OPAQUE_TYPES_H_