source: rtems/cpukit/score/src/threadmp.c @ 25f5730f

4.11
Last change on this file since 25f5730f was c499856, checked in by Chris Johns <chrisj@…>, on Mar 20, 2014 at 9:10:47 PM

Change all references of rtems.com to rtems.org.

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