summaryrefslogtreecommitdiffstats
path: root/cpukit/include/rtems/score/watchdogimpl.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--cpukit/include/rtems/score/watchdogimpl.h132
1 files changed, 84 insertions, 48 deletions
diff --git a/cpukit/include/rtems/score/watchdogimpl.h b/cpukit/include/rtems/score/watchdogimpl.h
index 7b364b8828..df479aeeed 100644
--- a/cpukit/include/rtems/score/watchdogimpl.h
+++ b/cpukit/include/rtems/score/watchdogimpl.h
@@ -1,3 +1,5 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+
/**
* @file
*
@@ -11,9 +13,26 @@
* COPYRIGHT (c) 1989-2004.
* On-Line Applications Research Corporation (OAR).
*
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rtems.org/license/LICENSE.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _RTEMS_SCORE_WATCHDOGIMPL_H
@@ -95,7 +114,7 @@ typedef enum {
*
* @param[out] header The header to initialize.
*/
-RTEMS_INLINE_ROUTINE void _Watchdog_Header_initialize(
+static inline void _Watchdog_Header_initialize(
Watchdog_Header *header
)
{
@@ -110,7 +129,7 @@ RTEMS_INLINE_ROUTINE void _Watchdog_Header_initialize(
*
* @return The first of @a header.
*/
-RTEMS_INLINE_ROUTINE Watchdog_Control *_Watchdog_Header_first(
+static inline Watchdog_Control *_Watchdog_Header_first(
const Watchdog_Header *header
)
{
@@ -122,7 +141,7 @@ RTEMS_INLINE_ROUTINE Watchdog_Control *_Watchdog_Header_first(
*
* @param header The watchdog header to destroy.
*/
-RTEMS_INLINE_ROUTINE void _Watchdog_Header_destroy(
+static inline void _Watchdog_Header_destroy(
Watchdog_Header *header
)
{
@@ -144,7 +163,7 @@ void _Watchdog_Tick( struct Per_CPU_Control *cpu );
*
* @return The RB_COLOR of @a the_watchdog.
*/
-RTEMS_INLINE_ROUTINE Watchdog_State _Watchdog_Get_state(
+static inline Watchdog_State _Watchdog_Get_state(
const Watchdog_Control *the_watchdog
)
{
@@ -157,7 +176,7 @@ RTEMS_INLINE_ROUTINE Watchdog_State _Watchdog_Get_state(
* @param[out] the_watchdog The watchdog to set the state of.
* @param state The state to set the watchdog to.
*/
-RTEMS_INLINE_ROUTINE void _Watchdog_Set_state(
+static inline void _Watchdog_Set_state(
Watchdog_Control *the_watchdog,
Watchdog_State state
)
@@ -172,7 +191,7 @@ RTEMS_INLINE_ROUTINE void _Watchdog_Set_state(
*
* @return The cpu of the watchdog.
*/
-RTEMS_INLINE_ROUTINE Per_CPU_Control *_Watchdog_Get_CPU(
+static inline Per_CPU_Control *_Watchdog_Get_CPU(
const Watchdog_Control *the_watchdog
)
{
@@ -189,7 +208,7 @@ RTEMS_INLINE_ROUTINE Per_CPU_Control *_Watchdog_Get_CPU(
* @param[out] the_watchdog The watchdog to set the cpu of.
* @param cpu The cpu to be set as @a the_watchdog's cpu.
*/
-RTEMS_INLINE_ROUTINE void _Watchdog_Set_CPU(
+static inline void _Watchdog_Set_CPU(
Watchdog_Control *the_watchdog,
Per_CPU_Control *cpu
)
@@ -209,7 +228,7 @@ RTEMS_INLINE_ROUTINE void _Watchdog_Set_CPU(
*
* @param[out] the_watchdog The uninitialized watchdog.
*/
-RTEMS_INLINE_ROUTINE void _Watchdog_Preinitialize(
+static inline void _Watchdog_Preinitialize(
Watchdog_Control *the_watchdog,
Per_CPU_Control *cpu
)
@@ -231,7 +250,7 @@ RTEMS_INLINE_ROUTINE void _Watchdog_Preinitialize(
* @param[out] the_watchdog The watchdog to initialize.
* @param routing The service routine for @a the_watchdog.
*/
-RTEMS_INLINE_ROUTINE void _Watchdog_Initialize(
+static inline void _Watchdog_Initialize(
Watchdog_Control *the_watchdog,
Watchdog_Service_routine_entry routine
)
@@ -313,7 +332,7 @@ void _Watchdog_Remove(
* @retval 0 The now time is greater than or equal to the expiration time of
* the watchdog.
*/
-RTEMS_INLINE_ROUTINE uint64_t _Watchdog_Cancel(
+static inline uint64_t _Watchdog_Cancel(
Watchdog_Header *header,
Watchdog_Control *the_watchdog,
uint64_t now
@@ -343,7 +362,7 @@ RTEMS_INLINE_ROUTINE uint64_t _Watchdog_Cancel(
* @retval true The watchdog is scheduled.
* @retval false The watchdog is inactive.
*/
-RTEMS_INLINE_ROUTINE bool _Watchdog_Is_scheduled(
+static inline bool _Watchdog_Is_scheduled(
const Watchdog_Control *the_watchdog
)
{
@@ -351,33 +370,50 @@ RTEMS_INLINE_ROUTINE bool _Watchdog_Is_scheduled(
}
/**
- * @brief Sets the first node of the header.
+ * @brief Sets the first watchdog of the watchdog collection to the next
+ * watchdog of the current first watchdog.
+ *
+ * This function may be used during watchdog removals, see _Watchdog_Remove()
+ * and _Watchdog_Tickle().
*
- * Sets the first node of the header to either the leftmost child node of the
- * watchdog control node, or if not present sets it to the right child node of
- * the watchdog control node. if both are not present, the new first node is
- * the parent node of the current first node.
+ * @param[in, out] header is the watchdog collection header.
*
- * @param[in, out] header The watchdog header.
- * @param the_watchdog The watchdog control node for the operation.
+ * @param first is the current first watchdog which should be removed
+ * afterwards.
*/
-RTEMS_INLINE_ROUTINE void _Watchdog_Next_first(
- Watchdog_Header *header,
- Watchdog_Control *the_watchdog
+static inline void _Watchdog_Next_first(
+ Watchdog_Header *header,
+ const Watchdog_Control *first
)
{
- RBTree_Node *node = _RBTree_Right( &the_watchdog->Node.RBTree );
-
- if ( node != NULL ) {
- RBTree_Node *left;
-
- while ( ( left = _RBTree_Left( node ) ) != NULL ) {
- node = left;
- }
+ RBTree_Node *right;
- header->first = node;
+ /*
+ * This function uses the following properties of red-black trees:
+ *
+ * 1. Every leaf (NULL) is black.
+ *
+ * 2. If a node is red, then both its children are black.
+ *
+ * 3. Every simple path from a node to a descendant leaf contains the same
+ * number of black nodes.
+ *
+ * The first node has no left child. So every path from the first node has
+ * exactly one black node (including leafs). The first node cannot have a
+ * non-leaf black right child. It may have a red right child. In this case
+ * both children must be leafs.
+ */
+ _Assert( header->first == &first->Node.RBTree );
+ _Assert( _RBTree_Left( &first->Node.RBTree ) == NULL );
+ right = _RBTree_Right( &first->Node.RBTree );
+
+ if ( right != NULL ) {
+ _Assert( RB_COLOR( right, Node ) == RB_RED );
+ _Assert( _RBTree_Left( right ) == NULL );
+ _Assert( _RBTree_Right( right ) == NULL );
+ header->first = right;
} else {
- header->first = _RBTree_Parent( &the_watchdog->Node.RBTree );
+ header->first = _RBTree_Parent( &first->Node.RBTree );
}
}
@@ -414,7 +450,7 @@ RTEMS_INLINE_ROUTINE void _Watchdog_Next_first(
* @retval true The timespec is a valid timespec.
* @retval false The timespec is invalid.
*/
-RTEMS_INLINE_ROUTINE bool _Watchdog_Is_valid_timespec(
+static inline bool _Watchdog_Is_valid_timespec(
const struct timespec *ts
)
{
@@ -430,7 +466,7 @@ RTEMS_INLINE_ROUTINE bool _Watchdog_Is_valid_timespec(
* @retval true The timespec is a valid interval timespec.
* @retval false The timespec is invalid.
*/
-RTEMS_INLINE_ROUTINE bool _Watchdog_Is_valid_interval_timespec(
+static inline bool _Watchdog_Is_valid_interval_timespec(
const struct timespec *ts
)
{
@@ -447,7 +483,7 @@ RTEMS_INLINE_ROUTINE bool _Watchdog_Is_valid_interval_timespec(
* @retval pointer Pointer to the now timespec.
* @retval NULL @a delta is not a valid interval timespec.
*/
-RTEMS_INLINE_ROUTINE const struct timespec * _Watchdog_Future_timespec(
+static inline const struct timespec * _Watchdog_Future_timespec(
struct timespec *now,
const struct timespec *delta
)
@@ -485,7 +521,7 @@ RTEMS_INLINE_ROUTINE const struct timespec * _Watchdog_Future_timespec(
* @retval true @a ts is too far in the future.
* @retval false @a ts is not too far in the future.
*/
-RTEMS_INLINE_ROUTINE bool _Watchdog_Is_far_future_timespec(
+static inline bool _Watchdog_Is_far_future_timespec(
const struct timespec *ts
)
{
@@ -499,7 +535,7 @@ RTEMS_INLINE_ROUTINE bool _Watchdog_Is_far_future_timespec(
*
* @return @a seconds converted to ticks.
*/
-RTEMS_INLINE_ROUTINE uint64_t _Watchdog_Ticks_from_seconds(
+static inline uint64_t _Watchdog_Ticks_from_seconds(
uint32_t seconds
)
{
@@ -517,7 +553,7 @@ RTEMS_INLINE_ROUTINE uint64_t _Watchdog_Ticks_from_seconds(
*
* @return @a ts converted to ticks.
*/
-RTEMS_INLINE_ROUTINE uint64_t _Watchdog_Ticks_from_timespec(
+static inline uint64_t _Watchdog_Ticks_from_timespec(
const struct timespec *ts
)
{
@@ -541,7 +577,7 @@ RTEMS_INLINE_ROUTINE uint64_t _Watchdog_Ticks_from_timespec(
*
* @param[out] ts is the timespec to return the converted ticks.
*/
-RTEMS_INLINE_ROUTINE void _Watchdog_Ticks_to_timespec(
+static inline void _Watchdog_Ticks_to_timespec(
uint64_t ticks,
struct timespec *ts
)
@@ -557,7 +593,7 @@ RTEMS_INLINE_ROUTINE void _Watchdog_Ticks_to_timespec(
*
* @return @a sbt converted to ticks.
*/
-RTEMS_INLINE_ROUTINE uint64_t _Watchdog_Ticks_from_sbintime( int64_t sbt )
+static inline uint64_t _Watchdog_Ticks_from_sbintime( int64_t sbt )
{
uint64_t ticks = ( sbt >> 32 ) << WATCHDOG_BITS_FOR_1E9_NANOSECONDS;
@@ -572,7 +608,7 @@ RTEMS_INLINE_ROUTINE uint64_t _Watchdog_Ticks_from_sbintime( int64_t sbt )
* @param cpu The cpu to acquire the watchdog lock of.
* @param lock_context The lock context.
*/
-RTEMS_INLINE_ROUTINE void _Watchdog_Per_CPU_acquire_critical(
+static inline void _Watchdog_Per_CPU_acquire_critical(
Per_CPU_Control *cpu,
ISR_lock_Context *lock_context
)
@@ -586,7 +622,7 @@ RTEMS_INLINE_ROUTINE void _Watchdog_Per_CPU_acquire_critical(
* @param cpu The cpu to release the watchdog lock of.
* @param lock_context The lock context.
*/
-RTEMS_INLINE_ROUTINE void _Watchdog_Per_CPU_release_critical(
+static inline void _Watchdog_Per_CPU_release_critical(
Per_CPU_Control *cpu,
ISR_lock_Context *lock_context
)
@@ -604,7 +640,7 @@ RTEMS_INLINE_ROUTINE void _Watchdog_Per_CPU_release_critical(
*
* @return The new expiration time of the watchdog.
*/
-RTEMS_INLINE_ROUTINE uint64_t _Watchdog_Per_CPU_insert_ticks(
+static inline uint64_t _Watchdog_Per_CPU_insert_ticks(
Watchdog_Control *the_watchdog,
Per_CPU_Control *cpu,
Watchdog_Interval ticks
@@ -636,7 +672,7 @@ RTEMS_INLINE_ROUTINE uint64_t _Watchdog_Per_CPU_insert_ticks(
*
* @return The expiration time of the watchdog.
*/
-RTEMS_INLINE_ROUTINE uint64_t _Watchdog_Per_CPU_insert(
+static inline uint64_t _Watchdog_Per_CPU_insert(
Watchdog_Control *the_watchdog,
Per_CPU_Control *cpu,
Watchdog_Header *header,
@@ -660,7 +696,7 @@ RTEMS_INLINE_ROUTINE uint64_t _Watchdog_Per_CPU_insert(
* @param cpu The cpu to remove the watchdog from.
* @param[in, out] The scheduled watchdogs.
*/
-RTEMS_INLINE_ROUTINE void _Watchdog_Per_CPU_remove(
+static inline void _Watchdog_Per_CPU_remove(
Watchdog_Control *the_watchdog,
Per_CPU_Control *cpu,
Watchdog_Header *header
@@ -681,7 +717,7 @@ RTEMS_INLINE_ROUTINE void _Watchdog_Per_CPU_remove(
*
* @param[in, out] the_watchdog The watchdog to remove.
*/
-RTEMS_INLINE_ROUTINE void _Watchdog_Per_CPU_remove_ticks(
+static inline void _Watchdog_Per_CPU_remove_ticks(
Watchdog_Control *the_watchdog
)
{