Subversion Repositories shark

Rev

Rev 881 | Rev 928 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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