[52adc808] | 1 | /** |
---|
| 2 | * @file |
---|
[ac7d5ef0] | 3 | * |
---|
[52adc808] | 4 | * @brief Semaphore MP Support |
---|
| 5 | * @ingroup ClassicSEM |
---|
| 6 | */ |
---|
| 7 | |
---|
| 8 | /* |
---|
[6c06288] | 9 | * COPYRIGHT (c) 1989-2008. |
---|
[ac7d5ef0] | 10 | * On-Line Applications Research Corporation (OAR). |
---|
| 11 | * |
---|
[98e4ebf5] | 12 | * The license and distribution terms for this file may be |
---|
| 13 | * found in the file LICENSE in this distribution or at |
---|
[c499856] | 14 | * http://www.rtems.org/license/LICENSE. |
---|
[ac7d5ef0] | 15 | */ |
---|
| 16 | |
---|
[1095ec1] | 17 | #if HAVE_CONFIG_H |
---|
| 18 | #include "config.h" |
---|
| 19 | #endif |
---|
| 20 | |
---|
[2bbea657] | 21 | #include <rtems/rtems/semimpl.h> |
---|
[7f04cb18] | 22 | #include <rtems/rtems/optionsimpl.h> |
---|
[dce48791] | 23 | #include <rtems/rtems/statusimpl.h> |
---|
[ac7d5ef0] | 24 | |
---|
[d689de0] | 25 | RTEMS_STATIC_ASSERT( |
---|
| 26 | sizeof(Semaphore_MP_Packet) <= MP_PACKET_MINIMUM_PACKET_SIZE, |
---|
| 27 | Semaphore_MP_Packet |
---|
| 28 | ); |
---|
| 29 | |
---|
[e38a92b] | 30 | static Semaphore_MP_Packet *_Semaphore_MP_Get_packet( void ) |
---|
| 31 | { |
---|
| 32 | return (Semaphore_MP_Packet *) _MPCI_Get_packet(); |
---|
| 33 | } |
---|
| 34 | |
---|
[ac7d5ef0] | 35 | void _Semaphore_MP_Send_process_packet ( |
---|
| 36 | Semaphore_MP_Remote_operations operation, |
---|
| 37 | Objects_Id semaphore_id, |
---|
[3235ad9] | 38 | rtems_name name, |
---|
[ac7d5ef0] | 39 | Objects_Id proxy_id |
---|
| 40 | ) |
---|
| 41 | { |
---|
| 42 | Semaphore_MP_Packet *the_packet; |
---|
[1d496f6] | 43 | uint32_t node; |
---|
[ac7d5ef0] | 44 | |
---|
| 45 | switch ( operation ) { |
---|
| 46 | |
---|
| 47 | case SEMAPHORE_MP_ANNOUNCE_CREATE: |
---|
| 48 | case SEMAPHORE_MP_ANNOUNCE_DELETE: |
---|
| 49 | case SEMAPHORE_MP_EXTRACT_PROXY: |
---|
| 50 | |
---|
| 51 | the_packet = _Semaphore_MP_Get_packet(); |
---|
[3a4ae6c] | 52 | the_packet->Prefix.the_class = MP_PACKET_SEMAPHORE; |
---|
[ac7d5ef0] | 53 | the_packet->Prefix.length = sizeof ( Semaphore_MP_Packet ); |
---|
| 54 | the_packet->Prefix.to_convert = sizeof ( Semaphore_MP_Packet ); |
---|
| 55 | the_packet->operation = operation; |
---|
| 56 | the_packet->Prefix.id = semaphore_id; |
---|
| 57 | the_packet->name = name; |
---|
| 58 | the_packet->proxy_id = proxy_id; |
---|
| 59 | |
---|
| 60 | if ( operation == SEMAPHORE_MP_EXTRACT_PROXY ) |
---|
[6c06288] | 61 | node = _Objects_Get_node( semaphore_id ); |
---|
[ac7d5ef0] | 62 | else |
---|
| 63 | node = MPCI_ALL_NODES; |
---|
| 64 | |
---|
| 65 | _MPCI_Send_process_packet( node, &the_packet->Prefix ); |
---|
| 66 | break; |
---|
| 67 | |
---|
| 68 | case SEMAPHORE_MP_OBTAIN_REQUEST: |
---|
| 69 | case SEMAPHORE_MP_OBTAIN_RESPONSE: |
---|
| 70 | case SEMAPHORE_MP_RELEASE_REQUEST: |
---|
| 71 | case SEMAPHORE_MP_RELEASE_RESPONSE: |
---|
| 72 | break; |
---|
| 73 | } |
---|
| 74 | } |
---|
| 75 | |
---|
[62c528e6] | 76 | static rtems_status_code _Semaphore_MP_Send_request_packet( |
---|
[ac7d5ef0] | 77 | Objects_Id semaphore_id, |
---|
[3a4ae6c] | 78 | rtems_option option_set, |
---|
[62c528e6] | 79 | rtems_interval timeout, |
---|
| 80 | Semaphore_MP_Remote_operations operation |
---|
[ac7d5ef0] | 81 | ) |
---|
| 82 | { |
---|
| 83 | Semaphore_MP_Packet *the_packet; |
---|
[dce48791] | 84 | Status_Control status; |
---|
[ac7d5ef0] | 85 | |
---|
[6378978] | 86 | if ( !_Semaphore_MP_Is_remote( semaphore_id ) ) { |
---|
| 87 | return RTEMS_INVALID_ID; |
---|
| 88 | } |
---|
| 89 | |
---|
[ac7d5ef0] | 90 | switch ( operation ) { |
---|
| 91 | |
---|
| 92 | case SEMAPHORE_MP_OBTAIN_REQUEST: |
---|
| 93 | case SEMAPHORE_MP_RELEASE_REQUEST: |
---|
| 94 | |
---|
| 95 | the_packet = _Semaphore_MP_Get_packet(); |
---|
[3a4ae6c] | 96 | the_packet->Prefix.the_class = MP_PACKET_SEMAPHORE; |
---|
[ac7d5ef0] | 97 | the_packet->Prefix.length = sizeof ( Semaphore_MP_Packet ); |
---|
| 98 | the_packet->Prefix.to_convert = sizeof ( Semaphore_MP_Packet ); |
---|
| 99 | if ( ! _Options_Is_no_wait(option_set)) |
---|
| 100 | the_packet->Prefix.timeout = timeout; |
---|
| 101 | |
---|
| 102 | the_packet->operation = operation; |
---|
| 103 | the_packet->Prefix.id = semaphore_id; |
---|
| 104 | the_packet->option_set = option_set; |
---|
| 105 | |
---|
[dce48791] | 106 | status = _MPCI_Send_request_packet( |
---|
| 107 | _Objects_Get_node( semaphore_id ), |
---|
| 108 | &the_packet->Prefix, |
---|
| 109 | STATES_WAITING_FOR_SEMAPHORE |
---|
| 110 | ); |
---|
| 111 | return _Status_Get( status ); |
---|
[ac7d5ef0] | 112 | |
---|
| 113 | case SEMAPHORE_MP_ANNOUNCE_CREATE: |
---|
| 114 | case SEMAPHORE_MP_ANNOUNCE_DELETE: |
---|
| 115 | case SEMAPHORE_MP_EXTRACT_PROXY: |
---|
| 116 | case SEMAPHORE_MP_OBTAIN_RESPONSE: |
---|
| 117 | case SEMAPHORE_MP_RELEASE_RESPONSE: |
---|
| 118 | break; |
---|
| 119 | |
---|
| 120 | } |
---|
| 121 | /* |
---|
| 122 | * The following line is included to satisfy compilers which |
---|
| 123 | * produce warnings when a function does not end with a return. |
---|
| 124 | */ |
---|
| 125 | return RTEMS_SUCCESSFUL; |
---|
| 126 | } |
---|
| 127 | |
---|
[62c528e6] | 128 | rtems_status_code _Semaphore_MP_Obtain( |
---|
| 129 | rtems_id id, |
---|
| 130 | rtems_option option_set, |
---|
| 131 | rtems_interval timeout |
---|
| 132 | ) |
---|
| 133 | { |
---|
| 134 | return _Semaphore_MP_Send_request_packet( |
---|
| 135 | id, |
---|
| 136 | option_set, |
---|
| 137 | timeout, |
---|
| 138 | SEMAPHORE_MP_OBTAIN_REQUEST |
---|
| 139 | ); |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | rtems_status_code _Semaphore_MP_Release( rtems_id id ) |
---|
| 143 | { |
---|
| 144 | return _Semaphore_MP_Send_request_packet( |
---|
| 145 | id, |
---|
| 146 | 0, |
---|
| 147 | MPCI_DEFAULT_TIMEOUT, |
---|
| 148 | SEMAPHORE_MP_RELEASE_REQUEST |
---|
| 149 | ); |
---|
| 150 | } |
---|
| 151 | |
---|
[c506158c] | 152 | static void _Semaphore_MP_Send_response_packet ( |
---|
[ac7d5ef0] | 153 | Semaphore_MP_Remote_operations operation, |
---|
| 154 | Objects_Id semaphore_id, |
---|
| 155 | Thread_Control *the_thread |
---|
| 156 | ) |
---|
| 157 | { |
---|
| 158 | Semaphore_MP_Packet *the_packet; |
---|
| 159 | |
---|
| 160 | switch ( operation ) { |
---|
| 161 | |
---|
| 162 | case SEMAPHORE_MP_OBTAIN_RESPONSE: |
---|
| 163 | case SEMAPHORE_MP_RELEASE_RESPONSE: |
---|
| 164 | |
---|
| 165 | the_packet = ( Semaphore_MP_Packet *) the_thread->receive_packet; |
---|
| 166 | |
---|
| 167 | /* |
---|
| 168 | * The packet being returned already contains the class, length, and |
---|
| 169 | * to_convert fields, therefore they are not set in this routine. |
---|
| 170 | */ |
---|
| 171 | the_packet->operation = operation; |
---|
| 172 | the_packet->Prefix.id = the_packet->Prefix.source_tid; |
---|
| 173 | |
---|
| 174 | _MPCI_Send_response_packet( |
---|
[6c06288] | 175 | _Objects_Get_node( the_packet->Prefix.source_tid ), |
---|
[ac7d5ef0] | 176 | &the_packet->Prefix |
---|
| 177 | ); |
---|
| 178 | break; |
---|
| 179 | |
---|
| 180 | case SEMAPHORE_MP_ANNOUNCE_CREATE: |
---|
| 181 | case SEMAPHORE_MP_ANNOUNCE_DELETE: |
---|
| 182 | case SEMAPHORE_MP_EXTRACT_PROXY: |
---|
| 183 | case SEMAPHORE_MP_OBTAIN_REQUEST: |
---|
| 184 | case SEMAPHORE_MP_RELEASE_REQUEST: |
---|
| 185 | break; |
---|
| 186 | |
---|
| 187 | } |
---|
| 188 | } |
---|
| 189 | |
---|
| 190 | void _Semaphore_MP_Process_packet ( |
---|
| 191 | rtems_packet_prefix *the_packet_prefix |
---|
| 192 | ) |
---|
| 193 | { |
---|
| 194 | Semaphore_MP_Packet *the_packet; |
---|
| 195 | Thread_Control *the_thread; |
---|
| 196 | |
---|
| 197 | the_packet = (Semaphore_MP_Packet *) the_packet_prefix; |
---|
| 198 | |
---|
| 199 | switch ( the_packet->operation ) { |
---|
| 200 | |
---|
| 201 | case SEMAPHORE_MP_ANNOUNCE_CREATE: |
---|
| 202 | |
---|
[8afeb993] | 203 | _Objects_MP_Allocate_and_open( |
---|
| 204 | &_Semaphore_Information, |
---|
| 205 | the_packet->name, |
---|
| 206 | the_packet->Prefix.id, |
---|
| 207 | true |
---|
| 208 | ); |
---|
[ac7d5ef0] | 209 | |
---|
| 210 | _MPCI_Return_packet( the_packet_prefix ); |
---|
| 211 | break; |
---|
| 212 | |
---|
| 213 | case SEMAPHORE_MP_ANNOUNCE_DELETE: |
---|
| 214 | |
---|
| 215 | _Objects_MP_Close( &_Semaphore_Information, the_packet->Prefix.id ); |
---|
| 216 | |
---|
| 217 | _MPCI_Return_packet( the_packet_prefix ); |
---|
| 218 | break; |
---|
| 219 | |
---|
| 220 | case SEMAPHORE_MP_EXTRACT_PROXY: |
---|
| 221 | |
---|
| 222 | the_thread = _Thread_MP_Find_proxy( the_packet->proxy_id ); |
---|
| 223 | |
---|
| 224 | if ( ! _Thread_Is_null( the_thread ) ) |
---|
[22788bc] | 225 | _Thread_queue_Extract( the_thread ); |
---|
[ac7d5ef0] | 226 | |
---|
| 227 | _MPCI_Return_packet( the_packet_prefix ); |
---|
| 228 | break; |
---|
| 229 | |
---|
| 230 | case SEMAPHORE_MP_OBTAIN_REQUEST: |
---|
| 231 | |
---|
| 232 | the_packet->Prefix.return_code = rtems_semaphore_obtain( |
---|
| 233 | the_packet->Prefix.id, |
---|
| 234 | the_packet->option_set, |
---|
| 235 | the_packet->Prefix.timeout |
---|
| 236 | ); |
---|
| 237 | |
---|
[dd1a460e] | 238 | if ( the_packet->Prefix.return_code != RTEMS_PROXY_BLOCKING ) |
---|
[ac7d5ef0] | 239 | _Semaphore_MP_Send_response_packet( |
---|
| 240 | SEMAPHORE_MP_OBTAIN_RESPONSE, |
---|
| 241 | the_packet->Prefix.id, |
---|
| 242 | _Thread_Executing |
---|
| 243 | ); |
---|
| 244 | break; |
---|
| 245 | |
---|
| 246 | case SEMAPHORE_MP_OBTAIN_RESPONSE: |
---|
| 247 | case SEMAPHORE_MP_RELEASE_RESPONSE: |
---|
| 248 | |
---|
| 249 | the_thread = _MPCI_Process_response( the_packet_prefix ); |
---|
| 250 | |
---|
| 251 | _MPCI_Return_packet( the_packet_prefix ); |
---|
| 252 | break; |
---|
| 253 | |
---|
| 254 | case SEMAPHORE_MP_RELEASE_REQUEST: |
---|
| 255 | |
---|
| 256 | the_packet->Prefix.return_code = rtems_semaphore_release( |
---|
| 257 | the_packet->Prefix.id |
---|
| 258 | ); |
---|
| 259 | |
---|
| 260 | _Semaphore_MP_Send_response_packet( |
---|
| 261 | SEMAPHORE_MP_RELEASE_RESPONSE, |
---|
| 262 | the_packet->Prefix.id, |
---|
| 263 | _Thread_Executing |
---|
| 264 | ); |
---|
| 265 | break; |
---|
| 266 | } |
---|
| 267 | } |
---|
| 268 | |
---|
| 269 | void _Semaphore_MP_Send_object_was_deleted ( |
---|
[9809d6e0] | 270 | Thread_Control *the_proxy, |
---|
| 271 | Objects_Id mp_id |
---|
[ac7d5ef0] | 272 | ) |
---|
| 273 | { |
---|
| 274 | the_proxy->receive_packet->return_code = RTEMS_OBJECT_WAS_DELETED; |
---|
| 275 | |
---|
| 276 | _Semaphore_MP_Send_response_packet( |
---|
| 277 | SEMAPHORE_MP_OBTAIN_RESPONSE, |
---|
[9809d6e0] | 278 | mp_id, |
---|
[ac7d5ef0] | 279 | the_proxy |
---|
| 280 | ); |
---|
| 281 | |
---|
| 282 | } |
---|
| 283 | |
---|
| 284 | void _Semaphore_MP_Send_extract_proxy ( |
---|
[9d9b6b56] | 285 | Thread_Control *the_thread, |
---|
| 286 | Objects_Id id |
---|
[ac7d5ef0] | 287 | ) |
---|
| 288 | { |
---|
| 289 | _Semaphore_MP_Send_process_packet( |
---|
| 290 | SEMAPHORE_MP_EXTRACT_PROXY, |
---|
[9d9b6b56] | 291 | id, |
---|
[3235ad9] | 292 | (rtems_name) 0, |
---|
[ac7d5ef0] | 293 | the_thread->Object.id |
---|
| 294 | ); |
---|
| 295 | |
---|
| 296 | } |
---|
| 297 | |
---|
[a2d0f39] | 298 | #if defined(RTEMS_MULTIPROCESSING) |
---|
| 299 | void _Semaphore_Core_mutex_mp_support ( |
---|
| 300 | Thread_Control *the_thread, |
---|
| 301 | Objects_Id id |
---|
| 302 | ) |
---|
| 303 | { |
---|
| 304 | the_thread->receive_packet->return_code = RTEMS_SUCCESSFUL; |
---|
[50f32b11] | 305 | |
---|
[a2d0f39] | 306 | _Semaphore_MP_Send_response_packet( |
---|
| 307 | SEMAPHORE_MP_OBTAIN_RESPONSE, |
---|
| 308 | id, |
---|
| 309 | the_thread |
---|
| 310 | ); |
---|
| 311 | } |
---|
| 312 | #endif |
---|
| 313 | |
---|
| 314 | #if defined(RTEMS_MULTIPROCESSING) |
---|
| 315 | void _Semaphore_Core_semaphore_mp_support ( |
---|
| 316 | Thread_Control *the_thread, |
---|
| 317 | Objects_Id id |
---|
| 318 | ) |
---|
| 319 | { |
---|
| 320 | the_thread->receive_packet->return_code = RTEMS_SUCCESSFUL; |
---|
[50f32b11] | 321 | |
---|
[a2d0f39] | 322 | _Semaphore_MP_Send_response_packet( |
---|
| 323 | SEMAPHORE_MP_OBTAIN_RESPONSE, |
---|
| 324 | id, |
---|
| 325 | the_thread |
---|
| 326 | ); |
---|
| 327 | } |
---|
| 328 | #endif |
---|
[ac7d5ef0] | 329 | /* end of file */ |
---|