source: rtems/cpukit/score/src/threadmp.c @ fa6b0f5

4.104.114.84.95
Last change on this file since fa6b0f5 was a8eed23, checked in by Ralf Corsepius <ralf.corsepius@…>, on 01/27/05 at 05:57:05

Include config.h.

  • Property mode set to 100644
File size: 3.6 KB
Line 
1/*
2 *  Multiprocessing Support for the Thread Handler
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.rtems.com/license/LICENSE.
11 *
12 *  $Id$
13 */
14
15#if HAVE_CONFIG_H
16#include "config.h"
17#endif
18
19#include <rtems/system.h>
20#include <rtems/score/priority.h>
21#include <rtems/score/thread.h>
22#include <rtems/score/wkspace.h>
23#include <rtems/score/isr.h>
24
25/*PAGE
26 *
27 *  _Thread_MP_Handler_initialization
28 *
29 */
30
31void _Thread_MP_Handler_initialization (
32  uint32_t    maximum_proxies
33)
34{
35
36  _Chain_Initialize_empty( &_Thread_MP_Active_proxies );
37
38  if ( maximum_proxies == 0 ) {
39    _Chain_Initialize_empty( &_Thread_MP_Inactive_proxies );
40    return;
41  }
42
43
44  _Chain_Initialize(
45    &_Thread_MP_Inactive_proxies,
46    _Workspace_Allocate_or_fatal_error(
47      maximum_proxies * sizeof( Thread_Proxy_control )
48    ),
49    maximum_proxies,
50    sizeof( Thread_Proxy_control )
51  );
52
53}
54
55/*PAGE
56 *
57 *  _Thread_MP_Allocate_proxy
58 *
59 */
60
61Thread_Control *_Thread_MP_Allocate_proxy (
62  States_Control  the_state
63)
64{
65  Thread_Control       *the_thread;
66  Thread_Proxy_control *the_proxy;
67
68  the_thread = (Thread_Control *)_Chain_Get( &_Thread_MP_Inactive_proxies );
69
70  if ( !_Thread_Is_null( the_thread ) ) {
71
72    the_proxy = (Thread_Proxy_control *) the_thread;
73
74    _Thread_Executing->Wait.return_code = THREAD_STATUS_PROXY_BLOCKING;
75
76    the_proxy->receive_packet = _Thread_MP_Receive->receive_packet;
77
78    the_proxy->Object.id = _Thread_MP_Receive->receive_packet->source_tid;
79
80    the_proxy->current_priority =
81      _Thread_MP_Receive->receive_packet->source_priority;
82
83    the_proxy->current_state = _States_Set( STATES_DORMANT, the_state );
84
85    the_proxy->Wait = _Thread_Executing->Wait;
86
87    _Chain_Append( &_Thread_MP_Active_proxies, &the_proxy->Active );
88
89    return the_thread;
90  }
91
92  _Internal_error_Occurred(
93    INTERNAL_ERROR_CORE,
94    TRUE,
95    INTERNAL_ERROR_OUT_OF_PROXIES
96  );
97
98  /*
99   *  NOTE: The following return insures that the compiler will
100   *        think that all paths return a value.
101   */
102
103  return NULL;
104}
105
106/*PAGE
107 *
108 *  _Thread_MP_Find_proxy
109 *
110 */
111
112/*
113 *  The following macro provides the offset of the Active element
114 *  in the Thread_Proxy_control structure.  This is the logical
115 *  equivalent of the POSITION attribute in Ada.
116 */
117
118#define _Thread_MP_Proxy_Active_offset \
119     ((uint32_t  )&(((Thread_Proxy_control *)0))->Active)
120
121Thread_Control *_Thread_MP_Find_proxy (
122  Objects_Id  the_id
123)
124{
125
126  Chain_Node           *proxy_node;
127  Thread_Control       *the_thread;
128  ISR_Level             level;
129
130restart:
131
132  _ISR_Disable( level );
133
134    for (  proxy_node = _Thread_MP_Active_proxies.first;
135           !_Chain_Is_tail( &_Thread_MP_Active_proxies, proxy_node ) ;
136        ) {
137
138      the_thread = (Thread_Control *) _Addresses_Subtract_offset(
139                     proxy_node,
140                     _Thread_MP_Proxy_Active_offset
141                   );
142
143      if ( _Objects_Are_ids_equal( the_thread->Object.id, the_id ) ) {
144        _ISR_Enable( level );
145        return the_thread;
146      }
147
148      _ISR_Flash( level );
149
150      proxy_node = proxy_node->next;
151
152      /*
153       *  A proxy which is only dormant is not in a blocking state.
154       *  Therefore, we are looking at proxy which has been moved from
155       *  active to inactive chain (by an ISR) and need to restart
156       *  the search.
157       */
158
159      if ( _States_Is_only_dormant( the_thread->current_state ) ) {
160        _ISR_Enable( level );
161        goto restart;
162      }
163    }
164
165  _ISR_Enable( level );
166  return NULL;
167}
Note: See TracBrowser for help on using the repository browser.