Subversion Repositories shark

Rev

Rev 928 | Rev 985 | 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
127
   @retval FSF_ERR_BAD_ARGUMENT if obj_handle or mutex are NULL
128
   @retval FSF_ERR_SHARED_OBJ_NOT_INITIALIZED if the shared object identified
881 trimarchi 129
       by obj_id does not exist
928 trimarchi 130
   @retval FSF_ERR_NOT_SCHEDULED_CALLING_THREAD : if the calling thread is not
881 trimarchi 131
       scheduled under the FSF
928 trimarchi 132
   @retval FSF_ERR_INVALID_SCHEDULER_REPLY the scheduler is wrong or not
133
       running
134
   @retval FSF_ERR_NOT_CONTRACTED_SERVER if the server of the calling thread
881 trimarchi 135
       has been cancelled or it is not valid
136
*/
137
int fsf_get_shared_object_mutex
138
   (fsf_shared_obj_handle_t  obj_handle,
139
    pthread_mutex_t          **mutex);
140
 
141
 
142
/////////////////////////////////////////////////////
143
//                       CONTRACT PARAMETERS
144
/////////////////////////////////////////////////////
145
 
928 trimarchi 146
/**
147
   \ingroup shobjmodule
148
 
149
   The operation updates the specified contract parameters object by
150
   setting its critical sections to the specified input parameter.
151
 
152
 
153
   @param[in] contract the service contract
154
   @param[in] critical_sections list of critical sections accessed by tasks
155
       belonging to the contract
156
 
157
   @retval 0 if the operation is succesful
158
   @retval FSF_ERR_BAD_ARGUMENT :if any of the pointers is NULL or
881 trimarchi 159
       the size of the critical_sections structure is less than zero
160
       or grater than FSF_MAX_N_CRITICAL_SECTIONS
161
*/
162
int
163
fsf_set_contract_synchronization_parameters
164
  (fsf_contract_parameters_t     *contract,
165
   const fsf_critical_sections_t *critical_sections);
166
 
167
 
928 trimarchi 168
/**
169
   \ingroup shobjmodule
170
 
171
   The operation obtains from the specified contract parameters object
172
   its critical sections, and copies them to the places pointed to by
173
   the specified input parameter.  Only those critical_section_data
174
   records that are in use in the critical_sections structure are
175
   copied (according to its size field).
176
 
177
   @param[in] contract pointer to a contract
178
   @param[out] critical_sections list of critical sections to be filled
179
 
180
   @retval 0 if the operation is succesful
181
   @retval FSF_ERR_BAD_ARGUMENT if any of the pointers is NULL
889 trimarchi 182
*/
881 trimarchi 183
int
184
fsf_get_contract_synchronization_parameters
185
  (const fsf_contract_parameters_t *contract,
186
   fsf_critical_sections_t         *critical_sections);
187
 
188
 
189
#endif // _FSF_SHARED_OBJECTS_H_