[05df0a8] | 1 | /* |
---|
| 2 | * Thread Handler |
---|
| 3 | * |
---|
| 4 | * |
---|
[08311cc3] | 5 | * COPYRIGHT (c) 1989-1999. |
---|
[05df0a8] | 6 | * On-Line Applications Research Corporation (OAR). |
---|
| 7 | * |
---|
| 8 | * The license and distribution terms for this file may be |
---|
| 9 | * found in found in the file LICENSE in this distribution or at |
---|
[dd687d97] | 10 | * http://www.rtems.com/license/LICENSE. |
---|
[05df0a8] | 11 | * |
---|
| 12 | * $Id$ |
---|
| 13 | */ |
---|
| 14 | |
---|
[a8eed23] | 15 | #if HAVE_CONFIG_H |
---|
| 16 | #include "config.h" |
---|
| 17 | #endif |
---|
| 18 | |
---|
[05df0a8] | 19 | #include <rtems/system.h> |
---|
| 20 | #include <rtems/score/apiext.h> |
---|
| 21 | #include <rtems/score/context.h> |
---|
| 22 | #include <rtems/score/interr.h> |
---|
| 23 | #include <rtems/score/isr.h> |
---|
| 24 | #include <rtems/score/object.h> |
---|
| 25 | #include <rtems/score/priority.h> |
---|
| 26 | #include <rtems/score/states.h> |
---|
| 27 | #include <rtems/score/sysstate.h> |
---|
| 28 | #include <rtems/score/thread.h> |
---|
| 29 | #include <rtems/score/threadq.h> |
---|
| 30 | #include <rtems/score/userext.h> |
---|
| 31 | #include <rtems/score/wkspace.h> |
---|
| 32 | |
---|
| 33 | /*PAGE |
---|
| 34 | * |
---|
| 35 | * _Thread_Set_state |
---|
| 36 | * |
---|
| 37 | * This kernel routine sets the requested state in the THREAD. The |
---|
| 38 | * THREAD chain is adjusted if necessary. |
---|
| 39 | * |
---|
| 40 | * Input parameters: |
---|
| 41 | * the_thread - pointer to thread control block |
---|
| 42 | * state - state to be set |
---|
| 43 | * |
---|
| 44 | * Output parameters: NONE |
---|
| 45 | * |
---|
| 46 | * INTERRUPT LATENCY: |
---|
| 47 | * ready chain |
---|
| 48 | * select map |
---|
| 49 | */ |
---|
| 50 | |
---|
| 51 | void _Thread_Set_state( |
---|
| 52 | Thread_Control *the_thread, |
---|
[96d0b64] | 53 | States_Control state |
---|
[05df0a8] | 54 | ) |
---|
| 55 | { |
---|
[96d0b64] | 56 | ISR_Level level; |
---|
[05df0a8] | 57 | Chain_Control *ready; |
---|
| 58 | |
---|
| 59 | ready = the_thread->ready; |
---|
| 60 | _ISR_Disable( level ); |
---|
| 61 | if ( !_States_Is_ready( the_thread->current_state ) ) { |
---|
| 62 | the_thread->current_state = |
---|
| 63 | _States_Set( state, the_thread->current_state ); |
---|
| 64 | _ISR_Enable( level ); |
---|
| 65 | return; |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | the_thread->current_state = state; |
---|
| 69 | |
---|
| 70 | if ( _Chain_Has_only_one_node( ready ) ) { |
---|
| 71 | |
---|
| 72 | _Chain_Initialize_empty( ready ); |
---|
| 73 | _Priority_Remove_from_bit_map( &the_thread->Priority_map ); |
---|
| 74 | |
---|
| 75 | } else |
---|
| 76 | _Chain_Extract_unprotected( &the_thread->Object.Node ); |
---|
| 77 | |
---|
| 78 | _ISR_Flash( level ); |
---|
| 79 | |
---|
| 80 | if ( _Thread_Is_heir( the_thread ) ) |
---|
| 81 | _Thread_Calculate_heir(); |
---|
| 82 | |
---|
| 83 | if ( _Thread_Is_executing( the_thread ) ) |
---|
[aae7f1a1] | 84 | _Context_Switch_necessary = true; |
---|
[05df0a8] | 85 | |
---|
| 86 | _ISR_Enable( level ); |
---|
| 87 | } |
---|