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