RTEMS CPU Kit with SuperCore  4.11.3
rtl-indirect-ptr.h
Go to the documentation of this file.
1 /*
2  * COPYRIGHT (c) 2012 Chris Johns <chrisj@rtems.org>
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  */
17 #if !defined (_RTEMS_RTL_INDIRECT_PTR_H_)
18 #define _RTEMS_RTL_INDIRECT_PTR_H_
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif /* __cplusplus */
23 
24 #include <rtems/chain.h>
25 
31  void* pointer;
32 };
33 
34 typedef struct rtems_rtl_ptr_s rtems_rtl_ptr_t;
35 
41  size_t size;
42 };
43 
44 typedef struct rtems_rtl_sptr_s rtems_rtl_sptr_t;
45 
55 };
56 
58 
68 };
69 
71 
78 static inline void* rtems_rtl_ptr_get (rtems_rtl_ptr_t* handle)
79 {
80  return handle->pointer;
81 }
82 
89 static inline void rtems_rtl_ptr_set (rtems_rtl_ptr_t* handle, void* pointer)
90 {
91  handle->pointer = pointer;
92 }
93 
99 static inline void rtems_rtl_ptr_init (rtems_rtl_ptr_t* handle)
100 {
101  rtems_chain_set_off_chain (&handle->node);
102  handle->pointer = NULL;
103 }
104 
111 static inline bool rtems_rtl_ptr_null (rtems_rtl_ptr_t* handle)
112 {
113  return handle->pointer == NULL;
114 }
115 
123 static inline void rtems_rtl_ptr_move (rtems_rtl_ptr_t* dst, rtems_rtl_ptr_t* src)
124 {
125  /*
126  * We do not know which chain the src handle resides on so insert the dst
127  * handle after the src handle then extract the src handle.
128  */
131  dst->pointer = src->pointer;
132  rtems_rtl_ptr_init (src);
133 }
134 
141 #define rtems_rtl_ptr_type_get(_h, _t) ((_t*) rtems_rtl_ptr_get (_h))
142 
149 static inline void* rtems_rtl_sptr_get (rtems_rtl_sptr_t* handle)
150 {
151  return rtems_rtl_ptr_get (&handle->ptr);
152 }
153 
160 static inline void rtems_rtl_sptr_set (rtems_rtl_sptr_t* handle, void* pointer)
161 {
162  rtems_rtl_ptr_set (&handle->ptr, pointer);
163 }
164 
170 static inline void rtems_rtl_sptr_init (rtems_rtl_sptr_t* handle)
171 {
172  rtems_rtl_ptr_init (&handle->ptr);
173  handle->size = 0;
174 }
175 
182 static inline bool rtems_rtl_sptr_null (rtems_rtl_sptr_t* handle)
183 {
184  return rtems_rtl_ptr_null (&handle->ptr);
185 }
186 
194 static inline void rtems_rtl_sptr_move (rtems_rtl_sptr_t* dst, rtems_rtl_sptr_t* src)
195 {
196  rtems_rtl_ptr_move (&dst->ptr, &src->ptr);
197  dst->size = src->size;
198  src->size = 0;
199 }
200 
207 static inline size_t rtems_rtl_sptr_get_size (rtems_rtl_sptr_t* handle)
208 {
209  return handle->size;
210 }
211 
218 static inline void rtems_rtl_sptr_set_size (rtems_rtl_sptr_t* handle, size_t size)
219 {
220  handle->size = size;
221 }
222 
229 #define rtems_rtl_sptr_type_get(_h, _t) ((_t*) rtems_rtl_sptr_get (_h))
230 
231 #ifdef __cplusplus
232 }
233 #endif /* __cplusplus */
234 
235 #endif
This is used to manage each element (node) which is placed on a chain.
Definition: chain.h:65
RTEMS_INLINE_ROUTINE void rtems_chain_extract_unprotected(rtems_chain_node *the_node)
Extract the specified node from a chain (unprotected).
Definition: chain.h:584
rtems_chain_node node
Indirect pointers are held on lists.
Definition: rtl-indirect-ptr.h:30
rtems_rtl_ptr_t ptr
The indirect pointer.
Definition: rtl-indirect-ptr.h:40
rtems_chain_node node
Chain of indirect pointers.
Definition: rtl-indirect-ptr.h:66
void * pointer
The actual pointer.
Definition: rtl-indirect-ptr.h:31
RTEMS_INLINE_ROUTINE void rtems_chain_insert_unprotected(rtems_chain_node *after_node, rtems_chain_node *the_node)
See _Chain_Insert_unprotected().
Definition: chain.h:653
RTEMS_INLINE_ROUTINE void rtems_chain_set_off_chain(rtems_chain_node *node)
Set off chain.
Definition: chain.h:183
rtems_rtl_ptr_t ptr
The indirect pointer.
Definition: rtl-indirect-ptr.h:54
rtems_chain_node node
Chain of indirect pointers.
Definition: rtl-indirect-ptr.h:53
The RTL Indirect size and pointer.
Definition: rtl-indirect-ptr.h:39
A chain of indirect pointers for users to chain in applications.
Definition: rtl-indirect-ptr.h:52
rtems_rtl_sptr_t ptr
The indirect pointer.
Definition: rtl-indirect-ptr.h:67
Chain API.
The RTL Indirect pointer.
Definition: rtl-indirect-ptr.h:29
A chain of indirect sized pointers for users to chain in applications.
Definition: rtl-indirect-ptr.h:65
size_t size
The size of the memory block.
Definition: rtl-indirect-ptr.h:41