source: rtems/cpukit/rtems/src/semmp.c @ 7f6a24ab

4.104.114.84.95
Last change on this file since 7f6a24ab was 7f6a24ab, checked in by Joel Sherrill <joel.sherrill@…>, on 08/28/95 at 15:30:29

Added unused priority ceiling parameter to rtems_semaphore_create.

Rearranged code to created thread handler routines to initialize,
start, restart, and "close/delete" a thread.

Made internal threads their own object class. This now uses the
thread support routines for starting and initializing a thread.

Insured deleted tasks are freed to the Inactive pool associated with the
correct Information block.

Added an RTEMS API specific data area to the thread control block.

Beginnings of removing the word "rtems" from the core.

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