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_Timeout( Watchdog_Control *watchdog ) |
---|
26 | { |
---|
27 | Thread_Control *the_thread; |
---|
28 | Thread_queue_Context queue_context; |
---|
29 | Thread_Wait_flags wait_flags; |
---|
30 | bool unblock; |
---|
31 | |
---|
32 | the_thread = RTEMS_CONTAINER_OF( watchdog, Thread_Control, Timer.Watchdog ); |
---|
33 | |
---|
34 | _Thread_queue_Context_initialize( &queue_context ); |
---|
35 | _Thread_queue_Context_clear_priority_updates( &queue_context ); |
---|
36 | _Thread_Wait_acquire( the_thread, &queue_context ); |
---|
37 | |
---|
38 | wait_flags = _Thread_Wait_flags_get( the_thread ); |
---|
39 | |
---|
40 | if ( ( wait_flags & THREAD_WAIT_STATE_READY_AGAIN ) == 0 ) { |
---|
41 | Thread_Wait_flags wait_class; |
---|
42 | Thread_Wait_flags ready_again; |
---|
43 | bool success; |
---|
44 | |
---|
45 | _Thread_Wait_cancel( the_thread, &queue_context ); |
---|
46 | |
---|
47 | the_thread->Wait.return_code = STATUS_TIMEOUT; |
---|
48 | |
---|
49 | wait_class = wait_flags & THREAD_WAIT_CLASS_MASK; |
---|
50 | ready_again = wait_class | THREAD_WAIT_STATE_READY_AGAIN; |
---|
51 | success = _Thread_Wait_flags_try_change_release( |
---|
52 | the_thread, |
---|
53 | wait_class | THREAD_WAIT_STATE_INTEND_TO_BLOCK, |
---|
54 | ready_again |
---|
55 | ); |
---|
56 | |
---|
57 | if ( success ) { |
---|
58 | unblock = false; |
---|
59 | } else { |
---|
60 | _Assert( |
---|
61 | _Thread_Wait_flags_get( the_thread ) |
---|
62 | == ( wait_class | THREAD_WAIT_STATE_BLOCKED ) |
---|
63 | ); |
---|
64 | _Thread_Wait_flags_set( the_thread, ready_again ); |
---|
65 | unblock = true; |
---|
66 | } |
---|
67 | } else { |
---|
68 | unblock = false; |
---|
69 | } |
---|
70 | |
---|
71 | _Thread_Wait_release( the_thread, &queue_context ); |
---|
72 | _Thread_Priority_update( &queue_context ); |
---|
73 | |
---|
74 | if ( unblock ) { |
---|
75 | _Thread_Wait_tranquilize( the_thread ); |
---|
76 | _Thread_Unblock( the_thread ); |
---|
77 | |
---|
78 | #if defined(RTEMS_MULTIPROCESSING) |
---|
79 | if ( !_Objects_Is_local_id( the_thread->Object.id ) ) { |
---|
80 | _Thread_MP_Free_proxy( the_thread ); |
---|
81 | } |
---|
82 | #endif |
---|
83 | } |
---|
84 | } |
---|