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

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

mpci: Make _*_MP_Send_response_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
29void _Semaphore_MP_Send_process_packet (
30  Semaphore_MP_Remote_operations  operation,
31  Objects_Id                      semaphore_id,
32  rtems_name                      name,
33  Objects_Id                      proxy_id
34)
35{
36  Semaphore_MP_Packet *the_packet;
37  uint32_t             node;
38
39  switch ( operation ) {
40
41    case SEMAPHORE_MP_ANNOUNCE_CREATE:
42    case SEMAPHORE_MP_ANNOUNCE_DELETE:
43    case SEMAPHORE_MP_EXTRACT_PROXY:
44
45      the_packet                    = _Semaphore_MP_Get_packet();
46      the_packet->Prefix.the_class  = MP_PACKET_SEMAPHORE;
47      the_packet->Prefix.length     = sizeof ( Semaphore_MP_Packet );
48      the_packet->Prefix.to_convert = sizeof ( Semaphore_MP_Packet );
49      the_packet->operation         = operation;
50      the_packet->Prefix.id         = semaphore_id;
51      the_packet->name              = name;
52      the_packet->proxy_id          = proxy_id;
53
54      if ( operation == SEMAPHORE_MP_EXTRACT_PROXY )
55         node = _Objects_Get_node( semaphore_id );
56      else
57         node = MPCI_ALL_NODES;
58
59      _MPCI_Send_process_packet( node, &the_packet->Prefix );
60      break;
61
62    case SEMAPHORE_MP_OBTAIN_REQUEST:
63    case SEMAPHORE_MP_OBTAIN_RESPONSE:
64    case SEMAPHORE_MP_RELEASE_REQUEST:
65    case SEMAPHORE_MP_RELEASE_RESPONSE:
66      break;
67  }
68}
69
70rtems_status_code _Semaphore_MP_Send_request_packet (
71  Semaphore_MP_Remote_operations operation,
72  Objects_Id                     semaphore_id,
73  rtems_option                   option_set,
74  rtems_interval                 timeout
75)
76{
77  Semaphore_MP_Packet *the_packet;
78
79  switch ( operation ) {
80
81    case SEMAPHORE_MP_OBTAIN_REQUEST:
82    case SEMAPHORE_MP_RELEASE_REQUEST:
83
84      the_packet                    = _Semaphore_MP_Get_packet();
85      the_packet->Prefix.the_class  = MP_PACKET_SEMAPHORE;
86      the_packet->Prefix.length     = sizeof ( Semaphore_MP_Packet );
87      the_packet->Prefix.to_convert = sizeof ( Semaphore_MP_Packet );
88      if ( ! _Options_Is_no_wait(option_set))
89          the_packet->Prefix.timeout = timeout;
90
91      the_packet->operation         = operation;
92      the_packet->Prefix.id         = semaphore_id;
93      the_packet->option_set        = option_set;
94
95      return _MPCI_Send_request_packet(
96          _Objects_Get_node( semaphore_id ),
97          &the_packet->Prefix,
98          STATES_WAITING_FOR_SEMAPHORE,
99          RTEMS_TIMEOUT
100        );
101      break;
102
103    case SEMAPHORE_MP_ANNOUNCE_CREATE:
104    case SEMAPHORE_MP_ANNOUNCE_DELETE:
105    case SEMAPHORE_MP_EXTRACT_PROXY:
106    case SEMAPHORE_MP_OBTAIN_RESPONSE:
107    case SEMAPHORE_MP_RELEASE_RESPONSE:
108      break;
109
110  }
111  /*
112   *  The following line is included to satisfy compilers which
113   *  produce warnings when a function does not end with a return.
114   */
115  return RTEMS_SUCCESSFUL;
116}
117
118static void _Semaphore_MP_Send_response_packet (
119  Semaphore_MP_Remote_operations  operation,
120  Objects_Id                      semaphore_id,
121  Thread_Control                 *the_thread
122)
123{
124  Semaphore_MP_Packet *the_packet;
125
126  switch ( operation ) {
127
128    case SEMAPHORE_MP_OBTAIN_RESPONSE:
129    case SEMAPHORE_MP_RELEASE_RESPONSE:
130
131      the_packet = ( Semaphore_MP_Packet *) the_thread->receive_packet;
132
133/*
134 *  The packet being returned already contains the class, length, and
135 *  to_convert fields, therefore they are not set in this routine.
136 */
137      the_packet->operation = operation;
138      the_packet->Prefix.id = the_packet->Prefix.source_tid;
139
140      _MPCI_Send_response_packet(
141        _Objects_Get_node( the_packet->Prefix.source_tid ),
142        &the_packet->Prefix
143      );
144      break;
145
146    case SEMAPHORE_MP_ANNOUNCE_CREATE:
147    case SEMAPHORE_MP_ANNOUNCE_DELETE:
148    case SEMAPHORE_MP_EXTRACT_PROXY:
149    case SEMAPHORE_MP_OBTAIN_REQUEST:
150    case SEMAPHORE_MP_RELEASE_REQUEST:
151      break;
152
153  }
154}
155
156void _Semaphore_MP_Process_packet (
157  rtems_packet_prefix  *the_packet_prefix
158)
159{
160  Semaphore_MP_Packet *the_packet;
161  Thread_Control      *the_thread;
162
163  the_packet = (Semaphore_MP_Packet *) the_packet_prefix;
164
165  switch ( the_packet->operation ) {
166
167    case SEMAPHORE_MP_ANNOUNCE_CREATE:
168
169      _Objects_MP_Allocate_and_open(
170        &_Semaphore_Information,
171        the_packet->name,
172        the_packet->Prefix.id,
173        true
174      );
175
176      _MPCI_Return_packet( the_packet_prefix );
177      break;
178
179    case SEMAPHORE_MP_ANNOUNCE_DELETE:
180
181      _Objects_MP_Close( &_Semaphore_Information, the_packet->Prefix.id );
182
183      _MPCI_Return_packet( the_packet_prefix );
184      break;
185
186    case SEMAPHORE_MP_EXTRACT_PROXY:
187
188      the_thread = _Thread_MP_Find_proxy( the_packet->proxy_id );
189
190      if ( ! _Thread_Is_null( the_thread ) )
191        _Thread_queue_Extract( the_thread );
192
193      _MPCI_Return_packet( the_packet_prefix );
194      break;
195
196    case SEMAPHORE_MP_OBTAIN_REQUEST:
197
198      the_packet->Prefix.return_code = rtems_semaphore_obtain(
199        the_packet->Prefix.id,
200        the_packet->option_set,
201        the_packet->Prefix.timeout
202      );
203
204      if ( the_packet->Prefix.return_code != RTEMS_PROXY_BLOCKING )
205        _Semaphore_MP_Send_response_packet(
206           SEMAPHORE_MP_OBTAIN_RESPONSE,
207           the_packet->Prefix.id,
208           _Thread_Executing
209        );
210      break;
211
212    case SEMAPHORE_MP_OBTAIN_RESPONSE:
213    case SEMAPHORE_MP_RELEASE_RESPONSE:
214
215      the_thread = _MPCI_Process_response( the_packet_prefix );
216
217      _MPCI_Return_packet( the_packet_prefix );
218      break;
219
220    case SEMAPHORE_MP_RELEASE_REQUEST:
221
222      the_packet->Prefix.return_code = rtems_semaphore_release(
223        the_packet->Prefix.id
224      );
225
226      _Semaphore_MP_Send_response_packet(
227        SEMAPHORE_MP_RELEASE_RESPONSE,
228        the_packet->Prefix.id,
229        _Thread_Executing
230      );
231      break;
232  }
233}
234
235void _Semaphore_MP_Send_object_was_deleted (
236  Thread_Control *the_proxy,
237  Objects_Id      mp_id
238)
239{
240  the_proxy->receive_packet->return_code = RTEMS_OBJECT_WAS_DELETED;
241
242  _Semaphore_MP_Send_response_packet(
243    SEMAPHORE_MP_OBTAIN_RESPONSE,
244    mp_id,
245    the_proxy
246  );
247
248}
249
250void _Semaphore_MP_Send_extract_proxy (
251  Thread_Control *the_thread,
252  Objects_Id      id
253)
254{
255  _Semaphore_MP_Send_process_packet(
256    SEMAPHORE_MP_EXTRACT_PROXY,
257    id,
258    (rtems_name) 0,
259    the_thread->Object.id
260  );
261
262}
263
264Semaphore_MP_Packet *_Semaphore_MP_Get_packet ( void )
265{
266  return ( (Semaphore_MP_Packet *) _MPCI_Get_packet() );
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.