1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Rate Monotonic Timeout |
---|
5 | * @ingroup ClassicRateMon |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-2009. |
---|
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/rtems/ratemonimpl.h> |
---|
22 | |
---|
23 | void _Rate_monotonic_Timeout( Watchdog_Control *the_watchdog ) |
---|
24 | { |
---|
25 | Rate_monotonic_Control *the_period; |
---|
26 | Thread_Control *owner; |
---|
27 | ISR_lock_Context lock_context; |
---|
28 | Thread_Wait_flags wait_flags; |
---|
29 | |
---|
30 | the_period = RTEMS_CONTAINER_OF( the_watchdog, Rate_monotonic_Control, Timer ); |
---|
31 | owner = the_period->owner; |
---|
32 | |
---|
33 | _ISR_lock_ISR_disable( &lock_context ); |
---|
34 | _Rate_monotonic_Acquire_critical( owner, &lock_context ); |
---|
35 | wait_flags = _Thread_Wait_flags_get( owner ); |
---|
36 | |
---|
37 | if ( |
---|
38 | ( wait_flags & THREAD_WAIT_CLASS_PERIOD ) != 0 |
---|
39 | && owner->Wait.return_argument == the_period |
---|
40 | ) { |
---|
41 | bool unblock; |
---|
42 | bool success; |
---|
43 | |
---|
44 | owner->Wait.return_argument = NULL; |
---|
45 | |
---|
46 | success = _Thread_Wait_flags_try_change_critical( |
---|
47 | owner, |
---|
48 | RATE_MONOTONIC_INTEND_TO_BLOCK, |
---|
49 | RATE_MONOTONIC_READY_AGAIN |
---|
50 | ); |
---|
51 | if ( success ) { |
---|
52 | unblock = false; |
---|
53 | } else { |
---|
54 | _Assert( _Thread_Wait_flags_get( owner ) == RATE_MONOTONIC_BLOCKED ); |
---|
55 | _Thread_Wait_flags_set( owner, RATE_MONOTONIC_READY_AGAIN ); |
---|
56 | unblock = true; |
---|
57 | } |
---|
58 | |
---|
59 | _Rate_monotonic_Restart( the_period, owner, &lock_context ); |
---|
60 | |
---|
61 | if ( unblock ) { |
---|
62 | _Thread_Unblock( owner ); |
---|
63 | } |
---|
64 | } else { |
---|
65 | the_period->state = RATE_MONOTONIC_EXPIRED; |
---|
66 | _Rate_monotonic_Release( owner, &lock_context ); |
---|
67 | } |
---|
68 | } |
---|