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