RTEMS 6.1-rc2
Loading...
Searching...
No Matches
rtl-indirect-ptr.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/*
4 * COPYRIGHT (c) 2012, 2018 Chris Johns <chrisj@rtems.org>
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
26 */
36#if !defined (_RTEMS_RTL_INDIRECT_PTR_H_)
37#define _RTEMS_RTL_INDIRECT_PTR_H_
38
39#ifdef __cplusplus
40extern "C" {
41#endif /* __cplusplus */
42
43#include <rtems/chain.h>
44
50 void* pointer;
51};
52
53typedef struct rtems_rtl_ptr rtems_rtl_ptr;
54
60 size_t size;
61};
62
63typedef struct rtems_rtl_sptr rtems_rtl_sptr;
64
74};
75
77
87};
88
90
97static inline void* rtems_rtl_ptr_get (rtems_rtl_ptr* handle)
98{
99 return handle->pointer;
100}
101
108static inline void rtems_rtl_ptr_set (rtems_rtl_ptr* handle, void* pointer)
109{
110 handle->pointer = pointer;
111}
112
118static inline void rtems_rtl_ptr_init (rtems_rtl_ptr* handle)
119{
120 rtems_chain_set_off_chain (&handle->node);
121 handle->pointer = NULL;
122}
123
130static inline bool rtems_rtl_ptr_null (rtems_rtl_ptr* handle)
131{
132 return handle->pointer == NULL;
133}
134
142static inline void rtems_rtl_ptr_move (rtems_rtl_ptr* dst, rtems_rtl_ptr* src)
143{
144 /*
145 * We do not know which chain the src handle resides on so insert the dst
146 * handle after the src handle then extract the src handle.
147 */
148 rtems_chain_insert_unprotected (&src->node, &dst->node);
149 rtems_chain_extract_unprotected (&src->node);
150 dst->pointer = src->pointer;
151 rtems_rtl_ptr_init (src);
152}
153
160#define rtems_rtl_ptr_type_get(_h, _t) ((_t*) rtems_rtl_ptr_get (_h))
161
168static inline void* rtems_rtl_sptr_get (rtems_rtl_sptr* handle)
169{
170 return rtems_rtl_ptr_get (&handle->ptr);
171}
172
179static inline void rtems_rtl_sptr_set (rtems_rtl_sptr* handle, void* pointer)
180{
181 rtems_rtl_ptr_set (&handle->ptr, pointer);
182}
183
189static inline void rtems_rtl_sptr_init (rtems_rtl_sptr* handle)
190{
191 rtems_rtl_ptr_init (&handle->ptr);
192 handle->size = 0;
193}
194
201static inline bool rtems_rtl_sptr_null (rtems_rtl_sptr* handle)
202{
203 return rtems_rtl_ptr_null (&handle->ptr);
204}
205
213static inline void rtems_rtl_sptr_move (rtems_rtl_sptr* dst, rtems_rtl_sptr* src)
214{
215 rtems_rtl_ptr_move (&dst->ptr, &src->ptr);
216 dst->size = src->size;
217 src->size = 0;
218}
219
226static inline size_t rtems_rtl_sptr_get_size (rtems_rtl_sptr* handle)
227{
228 return handle->size;
229}
230
237static inline void rtems_rtl_sptr_set_size (rtems_rtl_sptr* handle, size_t size)
238{
239 handle->size = size;
240}
241
248#define rtems_rtl_sptr_type_get(_h, _t) ((_t*) rtems_rtl_sptr_get (_h))
249
250#ifdef __cplusplus
251}
252#endif /* __cplusplus */
253
254#endif
This header file provides the Chains API.
#define NULL
Requests a GPIO pin group configuration.
Definition: xil_types.h:54
This structure represents a chain node.
Definition: chain.h:78
Definition: rtl-indirect-ptr.h:71
rtems_rtl_ptr ptr
Definition: rtl-indirect-ptr.h:73
rtems_chain_node node
Definition: rtl-indirect-ptr.h:72
Definition: rtl-indirect-ptr.h:48
rtems_chain_node node
Definition: rtl-indirect-ptr.h:49
void * pointer
Definition: rtl-indirect-ptr.h:50
Definition: rtl-indirect-ptr.h:84
rtems_rtl_sptr ptr
Definition: rtl-indirect-ptr.h:86
rtems_chain_node node
Definition: rtl-indirect-ptr.h:85
Definition: rtl-indirect-ptr.h:58
rtems_rtl_ptr ptr
Definition: rtl-indirect-ptr.h:59
size_t size
Definition: rtl-indirect-ptr.h:60