[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> |
---|
| 17 | #include <rtems/priority.h> |
---|
| 18 | #include <rtems/thread.h> |
---|
| 19 | #include <rtems/wkspace.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 = RTEMS_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 | rtems_fatal_error_occurred( RTEMS_TOO_MANY ); |
---|
| 89 | |
---|
| 90 | /* |
---|
| 91 | * NOTE: The following return insures that the compiler will |
---|
| 92 | * think that all paths return a value. |
---|
| 93 | */ |
---|
| 94 | |
---|
| 95 | return NULL; |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | /*PAGE |
---|
| 99 | * |
---|
| 100 | * _Thread_MP_Find_proxy |
---|
| 101 | * |
---|
| 102 | */ |
---|
| 103 | |
---|
| 104 | /* |
---|
| 105 | * The following macro provides the offset of the Active element |
---|
| 106 | * in the Thread_Proxy_control structure. This is the logical |
---|
| 107 | * equivalent of the POSITION attribute in Ada. |
---|
| 108 | */ |
---|
| 109 | |
---|
| 110 | #define _Thread_MP_Proxy_Active_offset \ |
---|
| 111 | ((unsigned32)&(((Thread_Proxy_control *)0))->Active) |
---|
| 112 | |
---|
| 113 | Thread_Control *_Thread_MP_Find_proxy ( |
---|
| 114 | Objects_Id the_id |
---|
| 115 | ) |
---|
| 116 | { |
---|
| 117 | |
---|
| 118 | Chain_Node *proxy_node; |
---|
| 119 | Thread_Control *the_thread; |
---|
| 120 | ISR_Level level; |
---|
| 121 | |
---|
| 122 | restart: |
---|
| 123 | |
---|
| 124 | _ISR_Disable( level ); |
---|
| 125 | |
---|
| 126 | for ( proxy_node = _Thread_MP_Active_proxies.first; |
---|
| 127 | !_Chain_Is_tail( &_Thread_MP_Active_proxies, proxy_node ) ; |
---|
| 128 | ) { |
---|
| 129 | |
---|
| 130 | the_thread = _Addresses_Subtract_offset( |
---|
| 131 | proxy_node, |
---|
| 132 | _Thread_MP_Proxy_Active_offset |
---|
| 133 | ); |
---|
| 134 | |
---|
| 135 | if ( _Objects_Are_ids_equal( the_thread->Object.id, the_id ) ) { |
---|
| 136 | _ISR_Enable( level ); |
---|
| 137 | return the_thread; |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | _ISR_Flash( level ); |
---|
| 141 | |
---|
| 142 | proxy_node = proxy_node->next; |
---|
| 143 | |
---|
| 144 | /* |
---|
| 145 | * A proxy which is only dormant is not in a blocking state. |
---|
| 146 | * Therefore, we are looking at proxy which has been moved from |
---|
| 147 | * active to inactive chain (by an ISR) and need to restart |
---|
| 148 | * the search. |
---|
| 149 | */ |
---|
| 150 | |
---|
| 151 | if ( _States_Is_only_dormant( the_thread->current_state ) ) { |
---|
| 152 | _ISR_Enable( level ); |
---|
| 153 | goto restart; |
---|
| 154 | } |
---|
| 155 | } |
---|
| 156 | |
---|
| 157 | _ISR_Enable( level ); |
---|
| 158 | return NULL; |
---|
| 159 | } |
---|