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