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

4.8
Last change on this file since b72e847b was 52502994, checked in by Joel Sherrill <joel.sherrill@…>, on 04/05/06 at 20:08:59

2006-04-05 Joel Sherrill <joel@…>

Victor V. Vengerov <Victor.Vengerov@…>

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