RTEMS
ratemontimeout.c
Go to the documentation of this file.
1 
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 #ifdef HAVE_CONFIG_H
20 #include "config.h"
21 #endif
22 
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 
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 
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 }
static __inline__ void _Thread_Unblock(Thread_Control *the_thread)
Unblocks the thread.
Definition: threadimpl.h:965
Thread_Wait_information Wait
Definition: thread.h:767
Watchdog_Control Timer
Protects the rate monotonic period state.
Definition: ratemondata.h:79
The control block used to manage each watchdog timer.
Definition: watchdog.h:90
static __inline__ Thread_Wait_flags _Thread_Wait_flags_get(const Thread_Control *the_thread)
Gets the thread's wait flags according to the ATOMIC_ORDER_RELAXED.
Definition: threadimpl.h:2215
Thread_Control * owner
Definition: ratemondata.h:100
#define RTEMS_CONTAINER_OF(_m, _type, _member_name)
Returns the pointer to the container of a specified member pointer.
Definition: basedefs.h:550
static __inline__ void _Thread_Wait_flags_set(Thread_Control *the_thread, Thread_Wait_flags flags)
Sets the thread's wait flags.
Definition: threadimpl.h:2196
unsigned int Thread_Wait_flags
This type is able to contain several flags used to control the wait class and state of a thread...
Definition: thread.h:383
static __inline__ bool _Thread_Wait_flags_try_change_release(Thread_Control *the_thread, Thread_Wait_flags expected_flags, Thread_Wait_flags desired_flags)
Tries to change the thread wait flags with release semantics in case of success.
Definition: threadimpl.h:2260
static __inline__ uint64_t _Watchdog_Per_CPU_insert_ticks(Watchdog_Control *the_watchdog, Per_CPU_Control *cpu, Watchdog_Interval ticks)
Sets the watchdog's cpu to the given instance and sets its expiration time to the watchdog expiration...
Definition: watchdogimpl.h:593
rtems_rate_monotonic_period_states state
Definition: ratemondata.h:82
The following structure defines the control block used to manage each period.
Definition: ratemondata.h:69
#define _ISR_lock_ISR_disable(_context)
Disables interrupts and saves the previous interrupt state in the ISR lock context.
Definition: isrlock.h:392
Classic Rate Monotonic Scheduler Implementation.
Local ISR lock context for acquire and release pairs.
Definition: isrlock.h:65
#define THREAD_WAIT_CLASS_PERIOD
Indicates that the thread waits for a period.
Definition: threadimpl.h:2188
#define _Assert(_e)
Assertion similar to assert() controlled via RTEMS_DEBUG instead of NDEBUG.
Definition: assert.h:100