Rev 929 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
929 | lipari | 1 | /** |
2 | @file Shared Objects |
||
3 | */ |
||
4 | |||
881 | trimarchi | 5 | //fsf_shared_objects.h |
6 | //================================================== |
||
7 | // FFFFFFIII RRRRR SSTTTTTTT |
||
8 | // FF IIR RR SS |
||
9 | // FF IR SS |
||
10 | // FFFFFF RRRR SSSSST |
||
11 | // FF FI RRR SS |
||
12 | // FF II RRR SS |
||
13 | // FF IIIIIR RS |
||
14 | // |
||
15 | // FSF(FIRST Scheduling Framework) |
||
16 | // shared objects functionality |
||
17 | //==================================================== |
||
18 | |||
19 | #include <pthread.h> |
||
20 | #include "fsf_basic_types.h" |
||
21 | #include "fsf_core.h" |
||
22 | |||
23 | #ifndef _FSF_SHARED_OBJECTS_H_ |
||
24 | #define _FSF_SHARED_OBJECTS_H_ |
||
25 | |||
26 | #define FSF_SHARED_OBJECTS_MODULE_SUPPORTED 1 |
||
27 | |||
28 | |||
29 | // These constants are defined in the fsf_configuration_parameters.h |
||
30 | // file: |
||
31 | |||
32 | //#define FSF_MAX_N_SHARED_OBJECTS 100 |
||
33 | //#define FSF_MAX_N_CRITICAL_SECTIONS 20 |
||
34 | |||
35 | |||
36 | //// The definition of this types is in fsf_basic_types.h |
||
37 | // |
||
38 | //// Shared object identifier (null character terminated string) |
||
39 | //typedef char * fsf_shared_obj_id_t; |
||
40 | // |
||
41 | //// Shared object handle (opaque type) |
||
42 | //typedef FSF_SHARED_OBJ_HANDLE_T_OPAQUE fsf_shared_obj_handle_t; |
||
43 | // |
||
44 | //// Critical section data |
||
45 | //typedef struct { |
||
46 | // fsf_shared_obj_handle_t obj_handle; |
||
47 | // struct timespec wcet; //Execution time |
||
48 | //} fsf_critical_section_data_t; |
||
49 | // |
||
50 | //// List of critical sections |
||
51 | //typedef struct { |
||
52 | // int size; // = 0 |
||
53 | // fsf_critical_section_data_t |
||
54 | // section[FSF_MAX_N_CRITICAL_SECTIONS]; |
||
55 | //} fsf_critical_sections_t; |
||
56 | // |
||
57 | |||
58 | ///////////////////////////////////////////////////// |
||
59 | // SHARED OBJECTS & OPERATIONS MANAGEMENT |
||
60 | ///////////////////////////////////////////////////// |
||
61 | |||
928 | trimarchi | 62 | /** |
63 | \ingroup shobjmodule |
||
64 | |||
65 | Initialization of shared objects. If the object identified by |
||
66 | obj_id does not yet exist it is created, a handle to the object is |
||
67 | returned in the variable pointed to by obj_handle, and the |
||
68 | specified mutex is initialized with the appropriate attributes |
||
69 | necessary for the current implementation. If the object already |
||
70 | exists, the function fails. |
||
71 | |||
72 | @param [in] obj_id shared object id |
||
73 | @param [out] obj_handle pointer to a shared object handle |
||
74 | @param [out] mutex pointer to a mutex variable |
||
75 | |||
76 | @retval 0 if the operation is succesful |
||
77 | @retval FSF_ERR_BAD_ARGUMENT if obj_id, obj_handle, or mutex are NULL |
||
78 | @retval FSF_ERR_SHARED_OBJ_ALREADY_INITIALIZED if the object identified |
||
881 | trimarchi | 79 | by obj_id already exists |
928 | trimarchi | 80 | @retval others It may also return any of the error codes that are |
81 | returned by the pthread_mutex_init() POSIX function call |
||
881 | trimarchi | 82 | */ |
83 | int fsf_init_shared_object |
||
84 | (fsf_shared_obj_id_t obj_id, |
||
85 | fsf_shared_obj_handle_t *obj_handle, |
||
86 | pthread_mutex_t *mutex); |
||
87 | |||
88 | |||
928 | trimarchi | 89 | /** |
90 | \ingroup shobjmodule |
||
91 | |||
92 | Getting the handle of shared |
||
93 | objects. If the object already exists a handle to the object is |
||
94 | returned in the variable pointed to by obj_handle. Otherwise, an |
||
95 | error code is returned by the function. |
||
96 | |||
97 | @param [in] obj_id shared object id |
||
98 | @param [out] obj_handle pointer to a shared object handle |
||
99 | |||
100 | @retval 0 if the operation is succesful |
||
101 | @retval FSF_ERR_BAD_ARGUMENT if obj_id or obj_handle are NULL |
||
102 | @retval FSF_ERR_SHARED_OBJ_NOT_INITIALIZED if the shared object identified |
||
881 | trimarchi | 103 | by obj_id does not exist |
928 | trimarchi | 104 | @retval FSF_ERR_NOT_SCHEDULED_CALLING_THREAD : if the calling thread is not |
881 | trimarchi | 105 | scheduled under the FSF |
928 | trimarchi | 106 | @retval FSF_ERR_INVALID_SCHEDULER_REPLY the scheduler is wrong or not |
107 | running |
||
108 | @retval FSF_ERR_NOT_CONTRACTED_SERVER : if the server of the calling |
||
109 | thread has been cancelled or it is not valid |
||
881 | trimarchi | 110 | */ |
111 | int fsf_get_shared_object_handle |
||
112 | (fsf_shared_obj_id_t obj_id, |
||
113 | fsf_shared_obj_handle_t *obj_handle); |
||
114 | |||
928 | trimarchi | 115 | /** |
116 | \ingroup shobjmodule |
||
117 | |||
118 | Getting the mutex of shared objects. If the object exists, a |
||
119 | pointer to its associated mutex is returned in the variable pointed |
||
120 | to by mutex. Otherwise, an error code is returned by the function. |
||
121 | |||
122 | @param [in] obj_handle shared object handle |
||
123 | @param [out] mutex pointer to a pointer to a mutex variable, |
||
124 | (remember that the function give back a pointer to a mutex!) |
||
125 | |||
126 | @retval 0 if the operation is succesful |
||
985 | julio | 127 | @retval FSF_ERR_BAD_ARGUMENT if obj_handle or mutex are NULL or obj_handle |
128 | is not correct or reference a wrong shared object |
||
928 | trimarchi | 129 | @retval FSF_ERR_NOT_SCHEDULED_CALLING_THREAD : if the calling thread is not |
881 | trimarchi | 130 | scheduled under the FSF |
928 | trimarchi | 131 | @retval FSF_ERR_INVALID_SCHEDULER_REPLY the scheduler is wrong or not |
132 | running |
||
133 | @retval FSF_ERR_NOT_CONTRACTED_SERVER if the server of the calling thread |
||
881 | trimarchi | 134 | has been cancelled or it is not valid |
135 | */ |
||
136 | int fsf_get_shared_object_mutex |
||
137 | (fsf_shared_obj_handle_t obj_handle, |
||
138 | pthread_mutex_t **mutex); |
||
139 | |||
140 | |||
141 | ///////////////////////////////////////////////////// |
||
142 | // CONTRACT PARAMETERS |
||
143 | ///////////////////////////////////////////////////// |
||
144 | |||
928 | trimarchi | 145 | /** |
146 | \ingroup shobjmodule |
||
147 | |||
148 | The operation updates the specified contract parameters object by |
||
149 | setting its critical sections to the specified input parameter. |
||
150 | |||
151 | |||
152 | @param[in] contract the service contract |
||
153 | @param[in] critical_sections list of critical sections accessed by tasks |
||
154 | belonging to the contract |
||
155 | |||
156 | @retval 0 if the operation is succesful |
||
157 | @retval FSF_ERR_BAD_ARGUMENT :if any of the pointers is NULL or |
||
881 | trimarchi | 158 | the size of the critical_sections structure is less than zero |
159 | or grater than FSF_MAX_N_CRITICAL_SECTIONS |
||
160 | */ |
||
161 | int |
||
162 | fsf_set_contract_synchronization_parameters |
||
163 | (fsf_contract_parameters_t *contract, |
||
164 | const fsf_critical_sections_t *critical_sections); |
||
165 | |||
166 | |||
928 | trimarchi | 167 | /** |
168 | \ingroup shobjmodule |
||
169 | |||
170 | The operation obtains from the specified contract parameters object |
||
171 | its critical sections, and copies them to the places pointed to by |
||
172 | the specified input parameter. Only those critical_section_data |
||
173 | records that are in use in the critical_sections structure are |
||
174 | copied (according to its size field). |
||
175 | |||
176 | @param[in] contract pointer to a contract |
||
177 | @param[out] critical_sections list of critical sections to be filled |
||
178 | |||
179 | @retval 0 if the operation is succesful |
||
180 | @retval FSF_ERR_BAD_ARGUMENT if any of the pointers is NULL |
||
889 | trimarchi | 181 | */ |
881 | trimarchi | 182 | int |
183 | fsf_get_contract_synchronization_parameters |
||
184 | (const fsf_contract_parameters_t *contract, |
||
185 | fsf_critical_sections_t *critical_sections); |
||
186 | |||
187 | |||
188 | #endif // _FSF_SHARED_OBJECTS_H_ |