summaryrefslogtreecommitdiffstats
path: root/cpukit/include
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2021-05-18 12:50:41 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2021-05-18 18:47:43 +0200
commita89ecaa1a94d49ddae7753d6b83923e9d2a00486 (patch)
tree2fccf3fd6b5a82f0415b497db190fbfa582a3866 /cpukit/include
parentposix: Fix use of clock for relative times (diff)
downloadrtems-a89ecaa1a94d49ddae7753d6b83923e9d2a00486.tar.bz2
score: Simplify thread queue timeout handling
Add Thread_queue_Context::timeout_absolute to specify an absolute or relative timeout. This avoid having to get the current time twice for timeouts relative to the current time. It moves also functionality to common code.
Diffstat (limited to 'cpukit/include')
-rw-r--r--cpukit/include/rtems/score/threadq.h9
-rw-r--r--cpukit/include/rtems/score/threadqimpl.h36
-rw-r--r--cpukit/include/rtems/score/watchdogimpl.h16
3 files changed, 48 insertions, 13 deletions
diff --git a/cpukit/include/rtems/score/threadq.h b/cpukit/include/rtems/score/threadq.h
index 5234019b81..10476888d4 100644
--- a/cpukit/include/rtems/score/threadq.h
+++ b/cpukit/include/rtems/score/threadq.h
@@ -214,7 +214,8 @@ struct Thread_queue_Context {
* callout must be used to install the thread watchdog for timeout handling.
*
* @see _Thread_queue_Enqueue_do_nothing_extra().
- * _Thread_queue_Add_timeout_ticks(), and
+ * _Thread_queue_Add_timeout_ticks(),
+ * _Thread_queue_Add_timeout_monotonic_timespec(), and
* _Thread_queue_Add_timeout_realtime_timespec().
*/
Thread_queue_Enqueue_callout enqueue_callout;
@@ -236,6 +237,12 @@ struct Thread_queue_Context {
const void *arg;
} Timeout;
+ /**
+ * @brief If this member is true, the timeout shall be absolute, otherwise it
+ * shall be relative to the current time of the clock.
+ */
+ bool timeout_absolute;
+
#if defined(RTEMS_SMP)
/**
* @brief Representation of a thread queue path from a start thread queue to
diff --git a/cpukit/include/rtems/score/threadqimpl.h b/cpukit/include/rtems/score/threadqimpl.h
index ca59de9e31..7b00de009d 100644
--- a/cpukit/include/rtems/score/threadqimpl.h
+++ b/cpukit/include/rtems/score/threadqimpl.h
@@ -267,41 +267,53 @@ _Thread_queue_Context_set_enqueue_timeout_ticks(
}
/**
- * @brief Sets the enqueue callout to add an absolute monotonic timeout in
- * timespec format.
+ * @brief Sets the enqueue callout to add a timeout in timespec format using
+ * CLOCK_MONOTONIC.
*
- * @param[out] queue_context The thread queue context.
- * @param abstime The absolute monotonic timeout.
+ * @param[out] queue_context is the thread queue context.
+ *
+ * @param timeout is the absolute or relative timeout.
+ *
+ * @param absolute is true, if the timeout shall be absolute, otherwise it
+ * shall be relative to the current time of the clock.
*
* @see _Thread_queue_Enqueue().
*/
RTEMS_INLINE_ROUTINE void
_Thread_queue_Context_set_enqueue_timeout_monotonic_timespec(
Thread_queue_Context *queue_context,
- const struct timespec *abstime
+ const struct timespec *timeout,
+ bool absolute
)
{
- queue_context->Timeout.arg = abstime;
+ queue_context->Timeout.arg = timeout;
+ queue_context->timeout_absolute = absolute;
queue_context->enqueue_callout =
_Thread_queue_Add_timeout_monotonic_timespec;
}
/**
- * @brief Sets the enqueue callout to add an absolute realtime timeout in
- * timespec format.
+ * @brief Sets the enqueue callout to add a timeout in timespec format using
+ * CLOCK_REALTIME.
*
- * @param[out] queue_context The thread queue context.
- * @param abstime The absolute realtime timeout.
+ * @param[out] queue_context is the thread queue context.
+ *
+ * @param timeout is the absolute or relative timeout.
+ *
+ * @param absolute is true, if the timeout shall be absolute, otherwise it
+ * shall be relative to the current time of the clock.
*
* @see _Thread_queue_Enqueue().
*/
RTEMS_INLINE_ROUTINE void
_Thread_queue_Context_set_enqueue_timeout_realtime_timespec(
Thread_queue_Context *queue_context,
- const struct timespec *abstime
+ const struct timespec *timeout,
+ bool absolute
)
{
- queue_context->Timeout.arg = abstime;
+ queue_context->Timeout.arg = timeout;
+ queue_context->timeout_absolute = absolute;
queue_context->enqueue_callout = _Thread_queue_Add_timeout_realtime_timespec;
}
diff --git a/cpukit/include/rtems/score/watchdogimpl.h b/cpukit/include/rtems/score/watchdogimpl.h
index a8e6de4fbe..7b364b8828 100644
--- a/cpukit/include/rtems/score/watchdogimpl.h
+++ b/cpukit/include/rtems/score/watchdogimpl.h
@@ -535,6 +535,22 @@ RTEMS_INLINE_ROUTINE uint64_t _Watchdog_Ticks_from_timespec(
}
/**
+ * @brief Converts the ticks to timespec.
+ *
+ * @param ticks are the ticks to convert.
+ *
+ * @param[out] ts is the timespec to return the converted ticks.
+ */
+RTEMS_INLINE_ROUTINE void _Watchdog_Ticks_to_timespec(
+ uint64_t ticks,
+ struct timespec *ts
+)
+{
+ ts->tv_sec = ticks >> WATCHDOG_BITS_FOR_1E9_NANOSECONDS;
+ ts->tv_nsec = ticks & ( ( 1U << WATCHDOG_BITS_FOR_1E9_NANOSECONDS ) - 1 );
+}
+
+/**
* @brief Converts the sbintime in ticks.
*
* @param sbt The sbintime to convert to ticks.