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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems-20020807/] [cpukit/] [score/] [src/] [threadmp.c] - Blame information for rev 1026

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

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

powered by: WebSVN 2.1.0

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