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 | * COPYRIGHT (c) 2016-2017 Kuan-Hsun Chen. |
---|
13 | * |
---|
14 | * The license and distribution terms for this file may be |
---|
15 | * found in the file LICENSE in this distribution or at |
---|
16 | * http://www.rtems.org/license/LICENSE. |
---|
17 | */ |
---|
18 | |
---|
19 | #if HAVE_CONFIG_H |
---|
20 | #include "config.h" |
---|
21 | #endif |
---|
22 | |
---|
23 | #include <rtems/rtems/ratemonimpl.h> |
---|
24 | |
---|
25 | static void _Rate_monotonic_Renew_deadline( |
---|
26 | Rate_monotonic_Control *the_period, |
---|
27 | ISR_lock_Context *lock_context |
---|
28 | ) |
---|
29 | { |
---|
30 | uint64_t deadline; |
---|
31 | |
---|
32 | /* stay at 0xffffffff if postponed_jobs is going to overflow */ |
---|
33 | if ( the_period->postponed_jobs != UINT32_MAX ) { |
---|
34 | ++the_period->postponed_jobs; |
---|
35 | } |
---|
36 | |
---|
37 | the_period->state = RATE_MONOTONIC_EXPIRED; |
---|
38 | |
---|
39 | deadline = _Watchdog_Per_CPU_insert_ticks( |
---|
40 | &the_period->Timer, |
---|
41 | _Per_CPU_Get(), |
---|
42 | the_period->next_length |
---|
43 | ); |
---|
44 | the_period->latest_deadline = deadline; |
---|
45 | |
---|
46 | _Rate_monotonic_Release( the_period, lock_context ); |
---|
47 | } |
---|
48 | |
---|
49 | void _Rate_monotonic_Timeout( Watchdog_Control *the_watchdog ) |
---|
50 | { |
---|
51 | Rate_monotonic_Control *the_period; |
---|
52 | Thread_Control *owner; |
---|
53 | ISR_lock_Context lock_context; |
---|
54 | Thread_Wait_flags wait_flags; |
---|
55 | |
---|
56 | the_period = RTEMS_CONTAINER_OF( the_watchdog, Rate_monotonic_Control, Timer ); |
---|
57 | owner = the_period->owner; |
---|
58 | |
---|
59 | _ISR_lock_ISR_disable( &lock_context ); |
---|
60 | _Rate_monotonic_Acquire_critical( the_period, &lock_context ); |
---|
61 | wait_flags = _Thread_Wait_flags_get( owner ); |
---|
62 | |
---|
63 | if ( |
---|
64 | ( wait_flags & THREAD_WAIT_CLASS_PERIOD ) != 0 |
---|
65 | && owner->Wait.return_argument == the_period |
---|
66 | ) { |
---|
67 | bool unblock; |
---|
68 | bool success; |
---|
69 | |
---|
70 | owner->Wait.return_argument = NULL; |
---|
71 | |
---|
72 | success = _Thread_Wait_flags_try_change_release( |
---|
73 | owner, |
---|
74 | RATE_MONOTONIC_INTEND_TO_BLOCK, |
---|
75 | RATE_MONOTONIC_READY_AGAIN |
---|
76 | ); |
---|
77 | if ( success ) { |
---|
78 | unblock = false; |
---|
79 | } else { |
---|
80 | _Assert( _Thread_Wait_flags_get( owner ) == RATE_MONOTONIC_BLOCKED ); |
---|
81 | _Thread_Wait_flags_set( owner, RATE_MONOTONIC_READY_AGAIN ); |
---|
82 | unblock = true; |
---|
83 | } |
---|
84 | |
---|
85 | _Rate_monotonic_Restart( the_period, owner, &lock_context ); |
---|
86 | |
---|
87 | if ( unblock ) { |
---|
88 | _Thread_Unblock( owner ); |
---|
89 | } |
---|
90 | } else { |
---|
91 | _Rate_monotonic_Renew_deadline( the_period, &lock_context ); |
---|
92 | } |
---|
93 | } |
---|