]> rtime.felk.cvut.cz Git - frescor/fosa.git/blob - include/fosa_types.h
Adding FOSA_CPP_BEING|END_DECLS to allow interfacing with C++
[frescor/fosa.git] / include / fosa_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_types.h
53 //==============================================
54 //  ********  ******    ********  **********
55 //  **///// /**    **  **//////  /**     /**
56 //  **      /**    ** /**        /**     /**
57 //  ******* /**    ** /********* /**********
58 //  **////  /**    ** ////////** /**//////**
59 //  **      /**    **        /** /**     /**
60 //  **      /**    **  ********  /**     /**
61 //  //       /******/  ////////   //      // 
62 //
63 // FOSA(Frescor Operating System Adaptation layer)
64 //================================================
65
66
67 #ifndef         _FOSA_TYPES_H_
68 #define         _FOSA_TYPES_H_
69
70 #include "fosa_opaque_types.h"
71
72 FOSA_CPP_BEGIN_DECLS
73
74 /**
75  * @addtogroup threadandsignals
76  *
77  * @{
78  **/  
79
80 /* Coming from FRSH-FOSA */
81
82 /** identifier of a FOSA thread **/
83 typedef FOSA_THREAD_ID_T_OPAQUE fosa_thread_id_t;
84
85
86 /** thread attributes object **/
87 typedef FOSA_THREAD_ATTR_T_OPAQUE fosa_thread_attr_t;
88
89 typedef FOSA_SIGNAL_T_OPAQUE fosa_signal_t;
90
91 /** 
92  *  The type references a function that may become a thread's
93  *  code
94  **/
95 typedef void * (*fosa_thread_code_t) (void *);
96
97
98 /** information associated to a signal **/
99 #if defined(VIRTUAL_TIME)
100
101 #include <vt_ose.h>
102 typedef vt_posix_signal_info_t fosa_signal_info_t;
103
104 #else
105
106 typedef union {int sival_int; void * sival_ptr; } fosa_signal_info_t;
107 /* typedef FOSA_SIGNAL_INFO_T_OPAQUE fosa_signal_info_t; */
108
109 #endif
110
111 /* @} */
112
113
114 /**
115  * @addtogroup clocksandtimers
116  *
117  * @{
118  **/  
119 // identifier of a clock
120 // either a real-time clock or a cpu-time clock
121 typedef    FOSA_CLOCK_ID_T_OPAQUE    fosa_clock_id_t;
122
123 #define FOSA_SYSTEM_CLOCK   FOSA_SYSTEM_CLOCK_OPAQUE
124
125 // identifier of a one-shot timer
126 typedef    FOSA_TIMER_ID_T_OPAQUE    fosa_timer_id_t;
127
128 /*@}*/
129
130 /**
131  * @addtrogroup mutexesandcondvars
132  *
133  * @{
134  **/
135 // a condition variable
136 /** Mutex object.  Attributes are handled by FOSA **/
137 typedef    FOSA_MUTEX_T_OPAQUE       fosa_mutex_t;
138
139 typedef    FOSA_COND_T_OPAQUE        fosa_cond_t;
140 /*@}*/
141
142 /**
143  * @addtogroup appdefsched
144  *
145  * @{
146  **/
147
148 /*********
149  *  ADS
150  *********/
151
152 /**
153  * ADS actions
154  *
155  * This type is used to represent a list of scheduling actions that the
156  * scheduler will later request to be executed by the system. The pos-
157  * sible actions are of the following kinds: 
158  *  - reject a thread that has requested attachment to this scheduler
159  *  - activate an application-scheduled thread with the desired value
160  *    of urgency
161  *  - suspend an application-scheduled thread
162  *  - program a timeout
163  *  - program a timed notification associated to a particular 
164  *    application-scheduled thread.
165  *
166  * No comparison or assignment operators are defined for this type
167  **/
168 typedef FOSA_ADS_ACTIONS_T_OPAQUE   fosa_ads_actions_t;
169
170 /* FOSA_ADS_ACTIONS_T_OPAQUE */
171
172 /**
173  * Causes of error in the appsched_error primitive operation
174  **/
175 typedef enum {FOSA_ADS_THREAD_NOT_ATTACHED, FOSA_ADS_INVALID_ACTION}
176     fosa_ads_error_cause_t;
177
178
179 /**
180  * The urgency used to orde the threads of the same priority in the
181  * underlying scheduler. Support for urgency scheduling is required
182  * for supporting the hierarchhical scheduling module
183  **/
184 typedef int fosa_ads_urgency_t;
185
186
187 /**
188  * Scheduler primitive operations
189  *
190  * This structure is used to create application schedulers. It
191  * contains pointers to the primitive operations that are invoked by
192  * the system when a scheduling event occurs:
193  *
194  * - The \b init() primitive operation is invoked by the system just after
195  *   the scheduler has been created using fosa_ads_scheduler_create().
196  *
197  * - The \b new_thread() primitive operation is invoked by the system when
198  *   a thread has requested attachment to this scheduler; this can be a
199  *   newly created thread (via fosa_thread_create()), or an existing thread
200  *   that was not running under ads scheduler (via
201  *   fosa_ads_set_appscheduled()).\n \n 
202  *   .
203  *   The thread can be rejected by the scheduler adding a
204  *   reject-thread action to the actions parameter using
205  *   fosa_ads_actions_add_reject(). If no reject-thread  action is
206  *   added, the thread is accepted.\n \n
207  *   .
208  *   Newly created threads shall be activated by the system after the
209  *   execution of the new_thread() primitive operation. The urgency of
210  *   an accepted thread (either newly created or existing) shall be set
211  *   to a value of zero, unless an activate-thread action with a
212  *   different value of urgency is added via
213  *   fosa_ads_actions_add_activate().\n \n
214  *   .
215  *   If a request to attach a thread to this scheduler was made via
216  *   fosa_ads_set_appscheduled(), at the finalization of the new_thread()
217  *   primitive operation if the newly attached thread is blocked by the
218  *   system (not by the scheduler itself via a suspend scheduling
219  *   action), a thread-block event shall be generated for the scheduler
220  *   immediately and, consequently, the thread_block() primitive
221  *   operation shall be invoked by the system.
222  *
223  * - The \b thread_terminate() primitive operation is invoked by the system
224  *   when a thread attached to this scheduler is terminating (via an
225  *   explicit or implicit thread termination, or cancellation, or when
226  *   it is no longer sceduled by the ads scheduler (via
227  *   fosa_ads_setappscheduled()). \n\n
228  *   .
229  *   Before the thread_terminate() primitive operation is invoked by
230  *   the system, all the thread-notification events programmed for that
231  *   thread are cancelled. \n\n
232  *   .
233  *   In the case of a thread that is terminating, the
234  *   thread_terminate() primitive operation is executed before the
235  *   execution of the cleanup handlers and of the thread-specific data
236  *   destructor functions. In that way, the thread parameter corresponds
237  *   to a valid thread Id and the thread-specific data is valid and can
238  *   be accessed from the thread_terminate() primitive operation. \n\n
239  *   .
240  *   Also for terminating threads, after the thread_terminate() primitive
241  *   operation finishes, the system shall lower the urgency of the
242  *   thread identified by thread to a value of zero, and shall deattach
243  *   it from the ads scheduler.  Then, the thread shall execute the
244  *   cleanup handlers and the thread-specific data destructor functions
245  *   outside the management of its former scheduler. Notice that in a
246  *   multiprocessor system this may imply the suspension of the thread
247  *   identified by parameter thread during the execution of the
248  *   thread_terminate() primitive operation.
249  *
250  * - The \b thread_ready() primitive operation is invoked by the system
251  *   when a thread attached to this scheduler that was blocked has
252  *   become unblocked by the system.
253  *
254  * - The \b thread_block() primitive operation is invoked by the system
255  *   when a thread attached to this scheduler has blocked.
256  * 
257  * - The \b change_sched_param_thread() primitive operation is invoked
258  *   by the system when the scheduling parameters of a thread attached
259  *   to this scheduler have been changed OUTSIDE OF AN SCHEDULER
260  *   CALLBACK, and the thread continues to run under this scheduler.
261  *   .
262  *   The change includes either the regular scheduling parameters
263  *   (fosa_thread_set_prio() or the application-defined scheduling
264  *   parameters, via fosa_ads_set_appsched_param(). 
265  *
266  * - The \b explicit_call_with_data() primitive operation is invoked by the
267  *   system when a thread (identified by the thread parameter) has
268  *   explicitly invoked the scheduler with a message containing
269  *   scheduling information, and possibly requesting a reply message,
270  *   via fosa_ads_invoke_withdata().
271  *
272  * - The \b notification_for_thread() primitive operation is invoked by the
273  *   system when the time for a thread-notification previously programed
274  *   by the scheduler via fosa_ads_actions_add_thread_notification()
275  *   is reached. Parameter clock identifies the clock for which the
276  *   thread-notification was programmed.
277  *
278  * - The \b timeout() primitive operation is invoked by the system when a
279  *   timeout requested by the scheduler (via
280  *   fosa_ads_actions_add_timeout()) has expired. 
281  *
282  * - The \b signal() primitive operation is invoked by the system when a
283  *   signal belonging to the set of signals for which the scheduler is
284  *   waiting (via fosa_ads_set_handled_signal_set()) has been
285  *   generated. \n\n
286  *   .
287  *   The signal number and its associated information (if any) are
288  *   passed in the arguments signal and siginfo.\n\n
289  *   .
290  *   The signal is consumed with the invocation of this primitive
291  *   operation, which implies that it will not cause the execution of
292  *   any signal handler, nor it may be accepted by any thread waiting
293  *   for this signal number.  
294  *
295  * - The \b appsched_error() primitive operation is invoked by the system
296  *   when an error in the scheduling actions list specified in a
297  *   previous primitive operation is detected. The cause of the error is
298  *   notified in the parameter cause. The defined causes of error are
299  *   described fosa_ads_error_cause_t
300  *
301  * Every primitive operation receives the argument sched_data. It is a
302  * pointer to a memory area containing information shared by all the
303  * scheduler operations. It can be used to store the data structures
304  * required by the scheduler (for example, a ready queue and a delay
305  * queue). Scheduler operations should not use any other global data out
306  * of this memory area.  
307  *
308  * The actions argument is used by the scheduler to request the operating
309  * system to execute a set of scheduling actions at the end of the
310  * primitive operation. It is passed empty by the system, and the
311  * scheduler may add multiple scheduling actions.
312  *
313  * The current_time argument contains the system time
314  * measured immediately before the invocation of the primitive operation
315  * using the FOSA_CLOCK_REALTIME clock
316  *
317  * In addition to these common parameters, most of the primitive
318  * operations receive a thread argument. This argument allows the
319  * primitive operations to know which is the thread that has produced or
320  * is related to the event. 
321  **/
322 typedef struct {
323    void (*init) (void * sched_data, void * arg);
324    void (*new_thread) (void * sched_data,
325             fosa_thread_id_t thread,
326             fosa_ads_actions_t * actions,
327             struct timespec *current_time);
328    void (*thread_terminate) (void * sched_data,
329             fosa_thread_id_t thread,
330             fosa_ads_actions_t * actions,
331             struct timespec *current_time);
332    void (*thread_ready) (void * sched_data,
333             fosa_thread_id_t thread,
334             fosa_ads_actions_t * actions,
335             struct timespec *current_time);
336    void (*thread_block) (void * sched_data,
337             fosa_thread_id_t thread,
338             fosa_ads_actions_t * actions,
339             struct timespec *current_time);
340   //void (*thread_yield) (void * sched_data,
341   //          fosa_thread_id_t thread,
342   //          fosa_ads_actions_t * actions,
343   //          struct timespec *current_time);
344    void (*change_sched_param_thread) (void * sched_data,
345             fosa_thread_id_t thread,
346             fosa_ads_actions_t * actions,
347             struct timespec *current_time);
348   //void msg_from_scheduler(void * sched_data,
349   //          fosa_ads_scheduler_id_t scheduler_id,
350   //          const void * msg, size_t msg_size,
351   //          fosa_ads_actions_t * actions,
352   //          struct timespec *current_time);
353   //void (*explicit_call) (void * sched_data,
354   //          fosa_thread_id_t thread,
355   //         int user_event_code,
356   //         fosa_ads_actions_t * actions,
357   //         struct timespec *current_time);
358   void (*explicit_call_with_data) (void * sched_data,
359            fosa_thread_id_t thread,
360            const void * msg, size_t msg_size,
361            void *reply, size_t *reply_size,
362            fosa_ads_actions_t * actions,
363            struct timespec *current_time);
364   void (*notification_for_thread) (void * sched_data,
365            fosa_thread_id_t thread,
366            fosa_clock_id_t clock,
367            fosa_ads_actions_t * actions,
368            struct timespec *current_time);
369   void (*timeout) (void * sched_data,
370            fosa_ads_actions_t * actions,
371            struct timespec *current_time);
372   void (*signal) (void * sched_data,
373            fosa_signal_t signal,
374            fosa_signal_info_t siginfo,
375            fosa_ads_actions_t * actions,
376            struct timespec *current_time);
377   //void (*priority_inherit) (void * sched_data,
378   //         fosa_thread_id_t thread,
379   //         int sched_priority,
380   //         fosa_ads_actions_t * actions,
381   //         struct timespec *current_time);
382   //void (*priority_uninherit) (void * sched_data,
383   //         fosa_thread_id_t thread,
384   //         int sched_priority,
385   //         fosa_ads_actions_t * actions,
386   //         struct timespec *current_time);
387   void (*appsched_error) (void * sched_data,
388            fosa_thread_id_t thread,
389            fosa_ads_error_cause_t cause,
390            fosa_ads_actions_t * actions);
391 } fosa_ads_scheduler_ops_t;
392
393
394 /*@}*/
395
396 /*********************
397  *   LONG JUMPS
398  *********************/
399
400 /**
401  * The fosa_jump_context_t type defines a data area where the context
402  * of a thread can be saved, so that a long jump to recover that context
403  * may be executed in the future, from a long jump handler.
404  */
405
406 typedef     FOSA_LONG_JUMP_CONTEXT_T_OPAQUE    fosa_long_jump_context_t; 
407
408
409 FOSA_CPP_END_DECLS
410
411
412 #endif // _FOSA_TYPES_H_