RTEMS CPU Kit with SuperCore  4.11.2
resourceimpl.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 embedded brains GmbH. All rights reserved.
3  *
4  * embedded brains GmbH
5  * Dornierstr. 4
6  * 82178 Puchheim
7  * Germany
8  * <rtems@embedded-brains.de>
9  *
10  * The license and distribution terms for this file may be
11  * found in the file LICENSE in this distribution or at
12  * http://www.rtems.org/license/LICENSE.
13  */
14 
15 #ifndef _RTEMS_SCORE_RESOURCEIMPL_H
16 #define _RTEMS_SCORE_RESOURCEIMPL_H
17 
18 #include <rtems/score/resource.h>
19 #include <rtems/score/chainimpl.h>
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif /* __cplusplus */
24 
42 typedef bool (*Resource_Node_visitor)( Resource_Node *node, void *arg );
43 
53  Resource_Node *top,
54  Resource_Node_visitor visitor,
55  void *arg
56 );
57 
58 RTEMS_INLINE_ROUTINE void _Resource_Node_initialize( Resource_Node *node )
59 {
60  node->dependency = NULL;
61  node->root = node;
63 }
64 
65 RTEMS_INLINE_ROUTINE void _Resource_Node_set_dependency(
66  Resource_Node *node,
67  Resource_Control *dependency
68 )
69 {
70  node->dependency = dependency;
71 }
72 
73 RTEMS_INLINE_ROUTINE Resource_Node *_Resource_Node_get_root(
74  const Resource_Node *node
75 )
76 {
77  return node->root;
78 }
79 
80 RTEMS_INLINE_ROUTINE void _Resource_Node_set_root(
81  Resource_Node *node,
82  Resource_Node *root
83 )
84 {
85  node->root = root;
86 }
87 
88 RTEMS_INLINE_ROUTINE bool _Resource_Node_owns_resources( const Resource_Node *node )
89 {
90  return !_Chain_Is_empty( &node->Resources );
91 }
92 
93 RTEMS_INLINE_ROUTINE void _Resource_Node_add_resource(
94  Resource_Node *node,
95  Resource_Control *resource
96 )
97 {
98  _Chain_Prepend_unprotected( &node->Resources, &resource->Node );
99 }
100 
101 RTEMS_INLINE_ROUTINE void _Resource_Node_extract( Resource_Node *node )
102 {
104 }
105 
106 RTEMS_INLINE_ROUTINE void _Resource_Initialize( Resource_Control *resource )
107 {
108  resource->owner = NULL;
109  _Chain_Initialize_empty( &resource->Rivals );
110 }
111 
112 RTEMS_INLINE_ROUTINE void _Resource_Add_rival(
113  Resource_Control *resource,
114  Resource_Node *node
115 )
116 {
117  _Chain_Append_unprotected( &resource->Rivals, &node->Node );
118 }
119 
120 RTEMS_INLINE_ROUTINE void _Resource_Extract( Resource_Control *resource )
121 {
122  _Chain_Extract_unprotected( &resource->Node );
123 }
124 
125 RTEMS_INLINE_ROUTINE Resource_Node *_Resource_Get_owner(
126  const Resource_Control *resource
127 )
128 {
129  return resource->owner;
130 }
131 
132 RTEMS_INLINE_ROUTINE void _Resource_Set_owner(
133  Resource_Control *resource,
134  Resource_Node *owner
135 )
136 {
137  resource->owner = owner;
138 }
139 
150  const Resource_Control *resource,
151  const Resource_Node *node
152 )
153 {
154  return &resource->Node == _Chain_Immutable_first( &node->Resources );
155 }
156 
159 #ifdef __cplusplus
160 }
161 #endif /* __cplusplus */
162 
163 #endif /* _RTEMS_SCORE_RESOURCEIMPL_H */
RTEMS_INLINE_ROUTINE void _Chain_Append_unprotected(Chain_Control *the_chain, Chain_Node *the_node)
Append a node (unprotected).
Definition: chainimpl.h:743
Resource_Control * dependency
Reference to a resource in case this node has to wait for ownership of this resource.
Definition: resource.h:171
#define RTEMS_INLINE_ROUTINE
The following (in conjunction with compiler arguments) are used to choose between the use of static i...
Definition: basedefs.h:135
RTEMS_INLINE_ROUTINE void _Chain_Extract_unprotected(Chain_Node *the_node)
Extract this node (unprotected).
Definition: chainimpl.h:639
RTEMS_INLINE_ROUTINE void _Chain_Initialize_empty(Chain_Control *the_chain)
Initialize this chain as empty.
Definition: chainimpl.h:613
Chain_Control Rivals
A chain of rivals waiting for resource ownership.
Definition: resource.h:198
Resource node to reflect ownership of resources and a dependency on a resource.
Definition: resource.h:150
RTEMS_INLINE_ROUTINE bool _Chain_Is_empty(const Chain_Control *the_chain)
Is the chain empty.
Definition: chainimpl.h:499
Resource_Node * owner
The owner of this resource.
Definition: resource.h:203
Chain_Node Node
Node to build a chain of rivals depending on a resource.
Definition: resource.h:156
Chain_Control Resources
A chain of resources owned by this node.
Definition: resource.h:163
RTEMS_INLINE_ROUTINE bool _Resource_Is_most_recently_obtained(const Resource_Control *resource, const Resource_Node *node)
Returns true if this is the most recently obtained resource of the node, and false otherwise...
Definition: resourceimpl.h:150
Resource_Node * root
Reference to the root of the resource tree.
Definition: resource.h:178
void _Resource_Iterate(Resource_Node *top, Resource_Node_visitor visitor, void *arg)
Iterates over all nodes of a resource dependency tree.
Definition: resourceiterate.c:28
RTEMS_INLINE_ROUTINE const Chain_Node * _Chain_Immutable_first(const Chain_Control *the_chain)
Return pointer to immutable chain&#39;s first node.
Definition: chainimpl.h:383
bool(* Resource_Node_visitor)(Resource_Node *node, void *arg)
Visitor function for resource node iteration.
Definition: resourceimpl.h:43
Chain Handler API.
Chain_Node Node
Node to build a chain of resources owned by a resource node.
Definition: resource.h:191
RTEMS_INLINE_ROUTINE void _Chain_Prepend_unprotected(Chain_Control *the_chain, Chain_Node *the_node)
Prepend a node (unprotected).
Definition: chainimpl.h:787
Resource control to manage ownership and rival nodes depending on a resource.
Definition: resource.h:185