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

Last change on this file since 3972085 was 3972085, checked in by Sebastian Huber <sebastian.huber@…>, on 10/13/20 at 11:47:06

Remove *_Is_null() inline functions

Simply compare the values against NULL.

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