[c18e0ba] | 1 | /** |
---|
[08fe84b] | 2 | * @file |
---|
[cc2bc302] | 3 | * |
---|
[08fe84b] | 4 | * @brief Thread Wait Timeout |
---|
| 5 | * |
---|
| 6 | * @ingroup ScoreThread |
---|
[c18e0ba] | 7 | */ |
---|
| 8 | |
---|
| 9 | /* |
---|
[3168deaa] | 10 | * COPYRIGHT (c) 1989-2008. |
---|
[cc2bc302] | 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 |
---|
[c499856] | 15 | * http://www.rtems.org/license/LICENSE. |
---|
[cc2bc302] | 16 | */ |
---|
| 17 | |
---|
[1095ec1] | 18 | #if HAVE_CONFIG_H |
---|
[736b8d2] | 19 | #include "config.h" |
---|
[1095ec1] | 20 | #endif |
---|
| 21 | |
---|
[5618c37a] | 22 | #include <rtems/score/threadimpl.h> |
---|
[cc2bc302] | 23 | |
---|
[08fe84b] | 24 | static void _Thread_Do_timeout( Thread_Control *the_thread ) |
---|
| 25 | { |
---|
| 26 | the_thread->Wait.return_code = the_thread->Wait.timeout_code; |
---|
[383cf42] | 27 | ( *the_thread->Wait.operations->extract )( |
---|
| 28 | the_thread->Wait.queue, |
---|
| 29 | the_thread |
---|
| 30 | ); |
---|
| 31 | _Thread_Wait_set_queue( the_thread, NULL ); |
---|
| 32 | _Thread_Wait_restore_default_operations( the_thread ); |
---|
[08fe84b] | 33 | _Thread_Lock_restore_default( the_thread ); |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | void _Thread_Timeout( Objects_Id id, void *arg ) |
---|
[cc2bc302] | 37 | { |
---|
[7d6e94b] | 38 | Thread_Control *the_thread; |
---|
[0e3c59d6] | 39 | void *thread_lock; |
---|
[7d6e94b] | 40 | ISR_lock_Context lock_context; |
---|
| 41 | Thread_Wait_flags wait_flags; |
---|
| 42 | Thread_Wait_flags wait_class; |
---|
| 43 | Thread_Wait_flags intend_to_block; |
---|
| 44 | Thread_Wait_flags blocked; |
---|
| 45 | bool success; |
---|
| 46 | bool unblock; |
---|
[736b8d2] | 47 | |
---|
[1041de1] | 48 | the_thread = arg; |
---|
[08fe84b] | 49 | thread_lock = _Thread_Lock_acquire( the_thread, &lock_context ); |
---|
[50f32b11] | 50 | |
---|
[1041de1] | 51 | wait_flags = _Thread_Wait_flags_get( the_thread ); |
---|
| 52 | wait_class = wait_flags & THREAD_WAIT_CLASS_MASK; |
---|
| 53 | intend_to_block = wait_class | THREAD_WAIT_STATE_INTEND_TO_BLOCK; |
---|
| 54 | blocked = wait_class | THREAD_WAIT_STATE_BLOCKED; |
---|
| 55 | success = _Thread_Wait_flags_try_change_critical( |
---|
| 56 | the_thread, |
---|
| 57 | intend_to_block, |
---|
[b7cff7fe] | 58 | wait_class | THREAD_WAIT_STATE_READY_AGAIN |
---|
[1041de1] | 59 | ); |
---|
[3168deaa] | 60 | |
---|
[1041de1] | 61 | if ( success ) { |
---|
[08fe84b] | 62 | _Thread_Do_timeout( the_thread ); |
---|
[1041de1] | 63 | unblock = false; |
---|
| 64 | } else if ( _Thread_Wait_flags_get( the_thread ) == blocked ) { |
---|
| 65 | _Thread_Wait_flags_set( |
---|
| 66 | the_thread, |
---|
[b7cff7fe] | 67 | wait_class | THREAD_WAIT_STATE_READY_AGAIN |
---|
[1041de1] | 68 | ); |
---|
[08fe84b] | 69 | _Thread_Do_timeout( the_thread ); |
---|
[1041de1] | 70 | unblock = true; |
---|
| 71 | } else { |
---|
| 72 | unblock = false; |
---|
| 73 | } |
---|
[ebe61382] | 74 | |
---|
[08fe84b] | 75 | _Thread_Lock_release( thread_lock, &lock_context ); |
---|
[7d6e94b] | 76 | |
---|
[1041de1] | 77 | if ( unblock ) { |
---|
| 78 | _Thread_Unblock( the_thread ); |
---|
[cc366ec] | 79 | |
---|
| 80 | #if defined(RTEMS_MULTIPROCESSING) |
---|
| 81 | if ( !_Objects_Is_local_id( the_thread->Object.id ) ) { |
---|
| 82 | _Thread_MP_Free_proxy( the_thread ); |
---|
| 83 | } |
---|
| 84 | #endif |
---|
[cc2bc302] | 85 | } |
---|
| 86 | } |
---|