source: rtems/cpukit/rtems/src/semmp.c @ 6b5f22dc

Last change on this file since 6b5f22dc was 6b5f22dc, checked in by Sebastian Huber <sebastian.huber@…>, on 11/26/20 at 10:45:47

rtems: Canonicalize Doxygen @file comments

Use common phrases for the file brief descriptions.

Update #3706.

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