OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [exec/] [rtems/] [src/] [semmp.c] - Blame information for rev 595

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.