1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Thread Wait Timeout |
---|
5 | * |
---|
6 | * @ingroup ScoreThread |
---|
7 | */ |
---|
8 | |
---|
9 | /* |
---|
10 | * COPYRIGHT (c) 1989-2008. |
---|
11 | * On-Line Applications Research Corporation (OAR). |
---|
12 | * |
---|
13 | * The license and distribution terms for this file may be |
---|
14 | * found in the file LICENSE in this distribution or at |
---|
15 | * http://www.rtems.org/license/LICENSE. |
---|
16 | */ |
---|
17 | |
---|
18 | #if HAVE_CONFIG_H |
---|
19 | #include "config.h" |
---|
20 | #endif |
---|
21 | |
---|
22 | #include <rtems/score/threadimpl.h> |
---|
23 | #include <rtems/score/status.h> |
---|
24 | |
---|
25 | void _Thread_Continue( Thread_Control *the_thread, Status_Control status ) |
---|
26 | { |
---|
27 | Thread_queue_Context queue_context; |
---|
28 | Thread_Wait_flags wait_flags; |
---|
29 | bool unblock; |
---|
30 | |
---|
31 | _Thread_queue_Context_initialize( &queue_context ); |
---|
32 | _Thread_queue_Context_clear_priority_updates( &queue_context ); |
---|
33 | _Thread_Wait_acquire( the_thread, &queue_context ); |
---|
34 | |
---|
35 | wait_flags = _Thread_Wait_flags_get( the_thread ); |
---|
36 | |
---|
37 | if ( ( wait_flags & THREAD_WAIT_STATE_READY_AGAIN ) == 0 ) { |
---|
38 | Thread_Wait_flags wait_class; |
---|
39 | Thread_Wait_flags ready_again; |
---|
40 | bool success; |
---|
41 | |
---|
42 | _Thread_Wait_cancel( the_thread, &queue_context ); |
---|
43 | |
---|
44 | the_thread->Wait.return_code = status; |
---|
45 | |
---|
46 | wait_class = wait_flags & THREAD_WAIT_CLASS_MASK; |
---|
47 | ready_again = wait_class | THREAD_WAIT_STATE_READY_AGAIN; |
---|
48 | success = _Thread_Wait_flags_try_change_release( |
---|
49 | the_thread, |
---|
50 | wait_class | THREAD_WAIT_STATE_INTEND_TO_BLOCK, |
---|
51 | ready_again |
---|
52 | ); |
---|
53 | |
---|
54 | if ( success ) { |
---|
55 | unblock = false; |
---|
56 | } else { |
---|
57 | _Assert( |
---|
58 | _Thread_Wait_flags_get( the_thread ) |
---|
59 | == ( wait_class | THREAD_WAIT_STATE_BLOCKED ) |
---|
60 | ); |
---|
61 | _Thread_Wait_flags_set( the_thread, ready_again ); |
---|
62 | unblock = true; |
---|
63 | } |
---|
64 | } else { |
---|
65 | unblock = false; |
---|
66 | } |
---|
67 | |
---|
68 | _Thread_Wait_release( the_thread, &queue_context ); |
---|
69 | _Thread_Priority_update( &queue_context ); |
---|
70 | |
---|
71 | if ( unblock ) { |
---|
72 | _Thread_Wait_tranquilize( the_thread ); |
---|
73 | _Thread_Unblock( the_thread ); |
---|
74 | |
---|
75 | #if defined(RTEMS_MULTIPROCESSING) |
---|
76 | if ( !_Objects_Is_local_id( the_thread->Object.id ) ) { |
---|
77 | _Thread_MP_Free_proxy( the_thread ); |
---|
78 | } |
---|
79 | #endif |
---|
80 | } |
---|
81 | } |
---|
82 | |
---|
83 | void _Thread_Timeout( Watchdog_Control *the_watchdog ) |
---|
84 | { |
---|
85 | Thread_Control *the_thread; |
---|
86 | |
---|
87 | the_thread = RTEMS_CONTAINER_OF( |
---|
88 | the_watchdog, |
---|
89 | Thread_Control, |
---|
90 | Timer.Watchdog |
---|
91 | ); |
---|
92 | _Thread_Continue( the_thread, STATUS_TIMEOUT ); |
---|
93 | } |
---|