1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Clear Thread state |
---|
5 | * @ingroup RTEMSScoreThread |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-2011. |
---|
10 | * On-Line Applications Research Corporation (OAR). |
---|
11 | * |
---|
12 | * The license and distribution terms for this file may be |
---|
13 | * found in the file LICENSE in this distribution or at |
---|
14 | * http://www.rtems.org/license/LICENSE. |
---|
15 | */ |
---|
16 | |
---|
17 | #if HAVE_CONFIG_H |
---|
18 | #include "config.h" |
---|
19 | #endif |
---|
20 | |
---|
21 | #include <rtems/score/threadimpl.h> |
---|
22 | #include <rtems/score/assert.h> |
---|
23 | #include <rtems/score/schedulerimpl.h> |
---|
24 | |
---|
25 | States_Control _Thread_Clear_state_locked( |
---|
26 | Thread_Control *the_thread, |
---|
27 | States_Control state |
---|
28 | ) |
---|
29 | { |
---|
30 | States_Control previous_state; |
---|
31 | |
---|
32 | _Assert( state != 0 ); |
---|
33 | _Assert( _Thread_State_is_owner( the_thread ) ); |
---|
34 | |
---|
35 | previous_state = the_thread->current_state; |
---|
36 | |
---|
37 | if ( ( previous_state & state ) != 0 ) { |
---|
38 | States_Control next_state; |
---|
39 | |
---|
40 | next_state = _States_Clear( state, previous_state ); |
---|
41 | the_thread->current_state = next_state; |
---|
42 | |
---|
43 | if ( _States_Is_ready( next_state ) ) { |
---|
44 | _Scheduler_Unblock( the_thread ); |
---|
45 | } |
---|
46 | } |
---|
47 | |
---|
48 | return previous_state; |
---|
49 | } |
---|
50 | |
---|
51 | States_Control _Thread_Clear_state( |
---|
52 | Thread_Control *the_thread, |
---|
53 | States_Control state |
---|
54 | ) |
---|
55 | { |
---|
56 | ISR_lock_Context lock_context; |
---|
57 | States_Control previous_state; |
---|
58 | |
---|
59 | _Thread_State_acquire( the_thread, &lock_context ); |
---|
60 | previous_state = _Thread_Clear_state_locked( the_thread, state ); |
---|
61 | _Thread_State_release( the_thread, &lock_context ); |
---|
62 | |
---|
63 | return previous_state; |
---|
64 | } |
---|