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

4.104.115
Last change on this file since eaef4657 was eaef4657, checked in by Ralf Corsepius <ralf.corsepius@…>, on 01/06/09 at 05:05:03

Eliminate TRUE/FALSE.

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