RTEMS
watchdoginsert.c
Go to the documentation of this file.
1 
9 /*
10  * Copyright (c) 2016 embedded brains GmbH. All rights reserved.
11  *
12  * embedded brains GmbH
13  * Dornierstr. 4
14  * 82178 Puchheim
15  * Germany
16  * <rtems@embedded-brains.de>
17  *
18  * The license and distribution terms for this file may be
19  * found in the file LICENSE in this distribution or at
20  * http://www.rtems.org/license/LICENSE.
21  */
22 
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26 
28 
30  Watchdog_Header *header,
31  Watchdog_Control *the_watchdog,
32  uint64_t expire
33 )
34 {
35  RBTree_Node **link;
36  RBTree_Node *parent;
37  RBTree_Node *old_first;
38  RBTree_Node *new_first;
39 
40  _Assert( _Watchdog_Get_state( the_watchdog ) == WATCHDOG_INACTIVE );
41 
42  link = _RBTree_Root_reference( &header->Watchdogs );
43  parent = NULL;
44  old_first = header->first;
45  new_first = &the_watchdog->Node.RBTree;
46 
47  the_watchdog->expire = expire;
48 
49  while ( *link != NULL ) {
50  Watchdog_Control *parent_watchdog;
51 
52  parent = *link;
53  parent_watchdog = (Watchdog_Control *) parent;
54 
55  if ( expire < parent_watchdog->expire ) {
56  link = _RBTree_Left_reference( parent );
57  } else {
58  link = _RBTree_Right_reference( parent );
59  new_first = old_first;
60  }
61  }
62 
63  header->first = new_first;
64  _RBTree_Initialize_node( &the_watchdog->Node.RBTree );
65  _RBTree_Add_child( &the_watchdog->Node.RBTree, parent, link );
66  _RBTree_Insert_color( &header->Watchdogs, &the_watchdog->Node.RBTree );
67 }
union Watchdog_Control::@33 Node
Nodes for the watchdog.
RBTree_Node * first
The scheduled watchdog with the earliest expiration time or NULL in case no watchdog is scheduled...
Definition: watchdog.h:81
The watchdog is inactive.
Definition: watchdogimpl.h:61
void _Watchdog_Insert(Watchdog_Header *header, Watchdog_Control *the_watchdog, uint64_t expire)
Inserts a watchdog into the set of scheduled watchdogs according to the specified expiration time...
Inlined Routines in the Watchdog Handler.
static __inline__ RBTree_Node ** _RBTree_Root_reference(RBTree_Control *the_rbtree)
Returns a reference to the root pointer of the red-black tree.
Definition: rbtree.h:261
static __inline__ Watchdog_State _Watchdog_Get_state(const Watchdog_Control *the_watchdog)
Gets the state of the watchdog.
Definition: watchdogimpl.h:149
uint64_t expire
This field is the expiration time point.
Definition: watchdog.h:117
The control block used to manage each watchdog timer.
Definition: watchdog.h:90
Red-black tree node.
Definition: rbtree.h:55
RBTree_Control Watchdogs
Red-black tree of scheduled watchdogs sorted by expiration time.
Definition: watchdog.h:75
static __inline__ void _RBTree_Add_child(RBTree_Node *child, RBTree_Node *parent, RBTree_Node **link)
Adds a child node to a parent node.
Definition: rbtree.h:145
RBTree_Node RBTree
this field is a red-black tree node structure and allows this to be placed on a red-black tree used t...
Definition: watchdog.h:99
void _RBTree_Insert_color(RBTree_Control *the_rbtree, RBTree_Node *the_node)
Rebalances the red-black tree after insertion of the node.
Definition: rbtreeinsert.c:17
static __inline__ RBTree_Node ** _RBTree_Left_reference(RBTree_Node *the_node)
Returns a reference to the left child pointer of the red-black tree node.
Definition: rbtree.h:326
The watchdog header to manage scheduled watchdogs.
Definition: watchdog.h:71
static __inline__ void _RBTree_Initialize_node(RBTree_Node *the_node)
Initializes a red-black tree node.
Definition: rbtree.h:129
static __inline__ RBTree_Node ** _RBTree_Right_reference(RBTree_Node *the_node)
Returns a reference to the right child pointer of the red-black tree node.
Definition: rbtree.h:357
#define _Assert(_e)
Assertion similar to assert() controlled via RTEMS_DEBUG instead of NDEBUG.
Definition: assert.h:100