RTEMS
threadqtimeout.c
1 /*
2  * Copyright (c) 2016, 2017 embedded brains GmbH
3  *
4  * The license and distribution terms for this file may be
5  * found in the file LICENSE in this distribution or at
6  * http://www.rtems.org/license/LICENSE.
7  */
8 
9 #ifdef HAVE_CONFIG_H
10 #include "config.h"
11 #endif
12 
14 #include <rtems/score/threadimpl.h>
16 
18  Thread_queue_Queue *queue,
19  Thread_Control *the_thread,
20  Per_CPU_Control *cpu_self,
21  Thread_queue_Context *queue_context
22 )
23 {
24  Watchdog_Interval ticks;
25 
26  ticks = queue_context->Timeout.ticks;
27 
28  if ( ticks != WATCHDOG_NO_TIMEOUT ) {
30  the_thread,
31  cpu_self,
32  queue_context->Timeout.ticks
33  );
34  }
35 }
36 
37 static void _Thread_queue_Add_timeout_timespec(
38  Thread_queue_Queue *queue,
39  Thread_Control *the_thread,
40  Per_CPU_Control *cpu_self,
41  Thread_queue_Context *queue_context,
42  Watchdog_Header *header,
43  const struct timespec *now
44 )
45 {
46  const struct timespec *abstime;
47 
48  abstime = queue_context->Timeout.arg;
49 
50  if ( _Watchdog_Is_valid_timespec( abstime ) ) {
51  uint64_t expire;
52 
53  if ( abstime->tv_sec < 0 ) {
54  expire = 0;
55  } else if ( _Watchdog_Is_far_future_timespec( abstime ) ) {
56  expire = WATCHDOG_MAXIMUM_TICKS;
57  } else {
58  expire = _Watchdog_Ticks_from_timespec( abstime );
59  }
60 
61  if ( expire > _Watchdog_Ticks_from_timespec( now ) ) {
62  ISR_lock_Context lock_context;
63 
65  &the_thread->Timer.Lock,
66  &lock_context
67  );
68 
69  the_thread->Timer.header = header;
70  the_thread->Timer.Watchdog.routine = _Thread_Timeout;
72  &the_thread->Timer.Watchdog,
73  cpu_self,
74  header,
75  expire
76  );
77 
79  &the_thread->Timer.Lock,
80  &lock_context
81  );
82  } else {
83  _Thread_Continue( the_thread, STATUS_TIMEOUT );
84  }
85  } else {
86  _Thread_Continue( the_thread, STATUS_INVALID_NUMBER );
87  }
88 }
89 
91  Thread_queue_Queue *queue,
92  Thread_Control *the_thread,
93  Per_CPU_Control *cpu_self,
94  Thread_queue_Context *queue_context
95 )
96 {
97  struct timespec now;
98 
100  _Thread_queue_Add_timeout_timespec(
101  queue,
102  the_thread,
103  cpu_self,
104  queue_context,
106  &now
107  );
108 }
109 
111  Thread_queue_Queue *queue,
112  Thread_Control *the_thread,
113  Per_CPU_Control *cpu_self,
114  Thread_queue_Context *queue_context
115 )
116 {
117  struct timespec now;
118 
119  _Timecounter_Getnanotime( &now );
120  _Thread_queue_Add_timeout_timespec(
121  queue,
122  the_thread,
123  cpu_self,
124  queue_context,
126  &now
127  );
128 }
Watchdog_Interval ticks
The timeout in ticks.
Definition: threadq.h:232
Index for realtime clock per-CPU watchdog header.
Definition: percpu.h:325
void _Timecounter_Getnanotime(struct timespec *ts)
Returns the wall clock time in the timespec format.
static __inline__ void _Thread_Add_timeout_ticks(Thread_Control *the_thread, Per_CPU_Control *cpu, Watchdog_Interval ticks)
Adds timeout ticks to the thread.
Definition: threadimpl.h:2405
uint32_t Watchdog_Interval
Type is used to specify the length of intervals.
Definition: watchdogticks.h:38
#define WATCHDOG_MAXIMUM_TICKS
The maximum watchdog ticks value for the far future.
Definition: watchdogimpl.h:389
#define _ISR_lock_Release_and_ISR_enable(_lock, _context)
Releases an ISR lock.
Definition: isrlock.h:257
Watchdog_Header Header[PER_CPU_WATCHDOG_COUNT]
Header for watchdogs.
Definition: percpu.h:474
Thread queue context for the thread queue methods.
Definition: threadq.h:198
static __inline__ uint64_t _Watchdog_Ticks_from_timespec(const struct timespec *ts)
Converts the timespec in ticks.
Definition: watchdogimpl.h:522
Inlined Routines in the Watchdog Handler.
void _Thread_Continue(Thread_Control *the_thread, Status_Control status)
Cancels a blocking operation so that the thread can continue its execution.
Definition: threadtimeout.c:25
static __inline__ bool _Watchdog_Is_valid_timespec(const struct timespec *ts)
Checks if the timespec is a valid timespec for a watchdog.
Definition: watchdogimpl.h:419
Watchdog_Service_routine_entry routine
This field is the function to invoke.
Definition: watchdog.h:114
static __inline__ uint64_t _Watchdog_Per_CPU_insert(Watchdog_Control *the_watchdog, Per_CPU_Control *cpu, Watchdog_Header *header, uint64_t expire)
Sets the watchdog&#39;s cpu and inserts it with the given expiration time in the scheduled watchdogs...
Definition: watchdogimpl.h:625
void _Thread_Timeout(Watchdog_Control *the_watchdog)
General purpose thread wait timeout.
Definition: threadtimeout.c:83
Per CPU Core Structure.
Definition: percpu.h:347
struct Per_CPU_Control::@13 Watchdog
Watchdog state for this processor.
Constants and Structures Associated with the Manipulation of Objects.
#define WATCHDOG_NO_TIMEOUT
Special watchdog ticks value to indicate an infinite wait.
Definition: watchdogticks.h:43
void _Thread_queue_Add_timeout_ticks(Thread_queue_Queue *queue, Thread_Control *the_thread, Per_CPU_Control *cpu_self, Thread_queue_Context *queue_context)
Adds timeout ticks of the queue to the thread.
void _Timecounter_Getnanouptime(struct timespec *ts)
Returns the uptime in the timespec format.
#define _ISR_lock_ISR_disable_and_acquire(_lock, _context)
Acquires an ISR lock.
Definition: isrlock.h:232
void _Thread_queue_Add_timeout_monotonic_timespec(Thread_queue_Queue *queue, Thread_Control *the_thread, Per_CPU_Control *cpu_self, Thread_queue_Context *queue_context)
Adds a monotonic timespec to the thread and sets the watchdog header to monotonic.
The watchdog header to manage scheduled watchdogs.
Definition: watchdog.h:71
Inlined Routines from the Thread Handler.
const void * arg
The timeout argument, e.g. pointer to struct timespec.
Definition: threadq.h:237
Index for monotonic clock per-CPU watchdog header.
Definition: percpu.h:334
void _Thread_queue_Add_timeout_realtime_timespec(Thread_queue_Queue *queue, Thread_Control *the_thread, Per_CPU_Control *cpu_self, Thread_queue_Context *queue_context)
Adds a monotonic timespec to the thread and sets the watchdog header to realtime. ...
Local ISR lock context for acquire and release pairs.
Definition: isrlock.h:65
static __inline__ bool _Watchdog_Is_far_future_timespec(const struct timespec *ts)
Checks if the timespec is too far in the future.
Definition: watchdogimpl.h:490
union Thread_queue_Context::@29 Timeout
Interval to wait.
Thread_Timer_information Timer
Definition: thread.h:769