source: rtems/cpukit/rtems/src/semmp.c @ e38a92b

5
Last change on this file since e38a92b was e38a92b, checked in by Sebastian Huber <sebastian.huber@…>, on 05/02/16 at 04:30:49

mpci: Make _*_MP_Get_packet() static

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