source: rtems/cpukit/rtems/src/semmp.c @ 98e4ebf

4.104.114.84.95
Last change on this file since 98e4ebf was 98e4ebf, checked in by Joel Sherrill <joel.sherrill@…>, on Oct 8, 1997 at 3:45:54 PM

Fixed typo in the pointer to the license terms.

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