RTEMS
6.3
Toggle main menu visibility
Loading...
Searching...
No Matches
cpukit
include
rtems
rtl
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
*/
35
36
#if !defined (_RTEMS_RTL_INDIRECT_PTR_H_)
37
#define _RTEMS_RTL_INDIRECT_PTR_H_
38
39
#ifdef __cplusplus
40
extern
"C"
{
41
#endif
/* __cplusplus */
42
43
#include <
rtems/chain.h
>
44
48
struct
rtems_rtl_ptr
{
49
rtems_chain_node
node
;
50
void
*
pointer
;
51
};
52
53
typedef
struct
rtems_rtl_ptr
rtems_rtl_ptr
;
54
58
struct
rtems_rtl_sptr
{
59
rtems_rtl_ptr
ptr
;
60
size_t
size
;
61
};
62
63
typedef
struct
rtems_rtl_sptr
rtems_rtl_sptr
;
64
71
struct
rtems_rtl_ptr_chain
{
72
rtems_chain_node
node
;
73
rtems_rtl_ptr
ptr
;
74
};
75
76
typedef
struct
rtems_rtl_ptr_chain
rtems_rtl_ptr_chain
;
77
84
struct
rtems_rtl_sptr_chain
{
85
rtems_chain_node
node
;
86
rtems_rtl_sptr
ptr
;
87
};
88
89
typedef
struct
rtems_rtl_sptr_chain
rtems_rtl_sptr_chain
;
90
97
static
inline
void
* rtems_rtl_ptr_get (
rtems_rtl_ptr
* handle)
98
{
99
return
handle->
pointer
;
100
}
101
108
static
inline
void
rtems_rtl_ptr_set (
rtems_rtl_ptr
* handle,
void
* pointer)
109
{
110
handle->
pointer
= pointer;
111
}
112
118
static
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
130
static
inline
bool
rtems_rtl_ptr_null (
rtems_rtl_ptr
* handle)
131
{
132
return
handle->
pointer
== NULL;
133
}
134
142
static
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
168
static
inline
void
* rtems_rtl_sptr_get (
rtems_rtl_sptr
* handle)
169
{
170
return
rtems_rtl_ptr_get (&handle->
ptr
);
171
}
172
179
static
inline
void
rtems_rtl_sptr_set (
rtems_rtl_sptr
* handle,
void
* pointer)
180
{
181
rtems_rtl_ptr_set (&handle->
ptr
, pointer);
182
}
183
189
static
inline
void
rtems_rtl_sptr_init (
rtems_rtl_sptr
* handle)
190
{
191
rtems_rtl_ptr_init (&handle->
ptr
);
192
handle->
size
= 0;
193
}
194
201
static
inline
bool
rtems_rtl_sptr_null (
rtems_rtl_sptr
* handle)
202
{
203
return
rtems_rtl_ptr_null (&handle->
ptr
);
204
}
205
213
static
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
226
static
inline
size_t
rtems_rtl_sptr_get_size (
rtems_rtl_sptr
* handle)
227
{
228
return
handle->
size
;
229
}
230
237
static
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
chain.h
This header file provides the Chains API.
rtems_rtl_ptr_chain
Definition
rtl-indirect-ptr.h:71
rtems_rtl_ptr_chain::ptr
rtems_rtl_ptr ptr
Definition
rtl-indirect-ptr.h:73
rtems_rtl_ptr_chain::node
rtems_chain_node node
Definition
rtl-indirect-ptr.h:72
rtems_rtl_ptr
Definition
rtl-indirect-ptr.h:48
rtems_rtl_ptr::node
rtems_chain_node node
Definition
rtl-indirect-ptr.h:49
rtems_rtl_ptr::pointer
void * pointer
Definition
rtl-indirect-ptr.h:50
rtems_rtl_sptr_chain
Definition
rtl-indirect-ptr.h:84
rtems_rtl_sptr_chain::ptr
rtems_rtl_sptr ptr
Definition
rtl-indirect-ptr.h:86
rtems_rtl_sptr_chain::node
rtems_chain_node node
Definition
rtl-indirect-ptr.h:85
rtems_rtl_sptr
Definition
rtl-indirect-ptr.h:58
rtems_rtl_sptr::ptr
rtems_rtl_ptr ptr
Definition
rtl-indirect-ptr.h:59
rtems_rtl_sptr::size
size_t size
Definition
rtl-indirect-ptr.h:60
Generated by
1.18.0