1 | /* |
---|
2 | * 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 found in the file LICENSE in this distribution or at |
---|
10 | * http://www.rtems.com/license/LICENSE. |
---|
11 | * |
---|
12 | * $Id$ |
---|
13 | */ |
---|
14 | |
---|
15 | #if HAVE_CONFIG_H |
---|
16 | #include "config.h" |
---|
17 | #endif |
---|
18 | |
---|
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_Suspend |
---|
36 | * |
---|
37 | * This kernel routine sets the SUSPEND state in the THREAD. The |
---|
38 | * THREAD chain and suspend count are adjusted if necessary. |
---|
39 | * |
---|
40 | * Input parameters: |
---|
41 | * the_thread - pointer to thread control block |
---|
42 | * |
---|
43 | * Output parameters: NONE |
---|
44 | * |
---|
45 | * INTERRUPT LATENCY: |
---|
46 | * ready chain |
---|
47 | * select map |
---|
48 | */ |
---|
49 | |
---|
50 | void _Thread_Suspend( |
---|
51 | Thread_Control *the_thread |
---|
52 | ) |
---|
53 | { |
---|
54 | ISR_Level level; |
---|
55 | Chain_Control *ready; |
---|
56 | |
---|
57 | ready = the_thread->ready; |
---|
58 | _ISR_Disable( level ); |
---|
59 | the_thread->suspend_count++; |
---|
60 | if ( !_States_Is_ready( the_thread->current_state ) ) { |
---|
61 | the_thread->current_state = |
---|
62 | _States_Set( STATES_SUSPENDED, the_thread->current_state ); |
---|
63 | _ISR_Enable( level ); |
---|
64 | return; |
---|
65 | } |
---|
66 | |
---|
67 | the_thread->current_state = STATES_SUSPENDED; |
---|
68 | |
---|
69 | if ( _Chain_Has_only_one_node( ready ) ) { |
---|
70 | |
---|
71 | _Chain_Initialize_empty( ready ); |
---|
72 | _Priority_Remove_from_bit_map( &the_thread->Priority_map ); |
---|
73 | |
---|
74 | } else |
---|
75 | _Chain_Extract_unprotected( &the_thread->Object.Node ); |
---|
76 | |
---|
77 | _ISR_Flash( level ); |
---|
78 | |
---|
79 | if ( _Thread_Is_heir( the_thread ) ) |
---|
80 | _Thread_Calculate_heir(); |
---|
81 | |
---|
82 | if ( _Thread_Is_executing( the_thread ) ) |
---|
83 | _Context_Switch_necessary = TRUE; |
---|
84 | |
---|
85 | _ISR_Enable( level ); |
---|
86 | } |
---|