2 * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 * @brief region manage
23 #ifndef _CL_REGION_H_ // NOLINT(build/header_guard)
24 #define _CL_REGION_H_ // NOLINT(build/header_guard)
30 #define CL_REGION_DEFAULT_SIZE (4 * 1024)
32 #define CL_ALIGNOF(type) __alignof(type)
34 typedef void (*cl_region_cleanup_pt)(void *data);
36 typedef struct cl_region_cleanup_s cl_region_cleanup_t;
38 /////////////////////////////////////////////////////////////////////////////////////
40 /// \~english @par Brief
41 /// region cleanup struct
42 /////////////////////////////////////////////////////////////////////////////////////
43 struct cl_region_cleanup_s { // NOLINT(readability/nolint)
44 cl_region_cleanup_pt handler;
46 cl_region_cleanup_t *next;
50 typedef struct cl_region_large_s cl_region_large_t;
52 /////////////////////////////////////////////////////////////////////////////////////
54 /// \~english @par Brief
55 /// region large struct
56 /////////////////////////////////////////////////////////////////////////////////////
57 struct cl_region_large_s { // NOLINT(readability/nolint)
58 cl_region_large_t *next;
64 typedef struct cl_region_s cl_region_t;
66 /////////////////////////////////////////////////////////////////////////////////////
68 /// \~english @par Brief
69 /// region data struct
70 /////////////////////////////////////////////////////////////////////////////////////
78 /////////////////////////////////////////////////////////////////////////////////////
80 /// \~english @par Brief
82 /////////////////////////////////////////////////////////////////////////////////////
83 struct cl_region_s { // NOLINT(readability/nolint)
87 cl_region_large_t *large;
88 cl_region_cleanup_t *cleanup;
99 /** @addtogroup BaseSystem
102 /** @addtogroup native_service
103 * @ingroup BaseSystem
106 /** @addtogroup common_library
107 * @ingroup native_service
111 /////////////////////////////////////////////////////////////////////////////////////
113 /// \~english @par Brief
115 /// \~english @param [in] size
116 /// size_t - the size to create
117 /// \~english @retval 0 Success
118 /// \~english @retval -1 Error
119 /// \~english @par Prerequisite
121 /// \~english @par Change of internal state
123 /// \~english @par Conditions of processing failure
125 /// \~english @par Classification
127 /// \~english @par Type
129 /// \~english @par Detail
131 /// \~english @see None
132 ////////////////////////////////////////////////////////////////////////////////////
133 cl_region_t *CL_RegionCreate(size_t size); // NOLINT(readability/nolint)
136 /////////////////////////////////////////////////////////////////////////////////////
138 /// \~english @par Brief
140 /// \~english @param [in] region
141 /// cl_region_t * - the region to destroy
142 /// \~english @retval 0 Success
143 /// \~english @retval -1 Error
144 /// \~english @par Prerequisite
146 /// \~english @par Change of internal state
148 /// \~english @par Conditions of processing failure
150 /// \~english @par Classification
152 /// \~english @par Type
154 /// \~english @par Detail
156 /// \~english @see None
157 ////////////////////////////////////////////////////////////////////////////////////
158 void CL_RegionDestroy(cl_region_t *region); // NOLINT(readability/nolint)
161 /////////////////////////////////////////////////////////////////////////////////////
163 /// \~english @par Brief
164 /// Region allocation
165 /// \~english @param [in] region
166 /// cl_region_t * - the region to allocate
167 /// \~english @param [in] size
168 /// size_t * - the size to allocate
169 /// \~english @param [in] align_size
170 /// size_t * - the size to align
171 /// \~english @retval the pointer to region allocated
172 /// \~english @par Prerequisite
174 /// \~english @par Change of internal state
176 /// \~english @par Conditions of processing failure
178 /// \~english @par Classification
180 /// \~english @par Type
182 /// \~english @par Detail
184 /// \~english @see None
185 ////////////////////////////////////////////////////////////////////////////////////
186 #define CL_RegionAlloc(region, type, length) \
187 cl_region_alloc(region, sizeof(type) * length, CL_ALIGNOF(type))
188 void *cl_region_alloc(cl_region_t *region, size_t size, size_t align_size); // NOLINT(readability/nolint)
190 /////////////////////////////////////////////////////////////////////////////////////
192 /// \~english @par Brief
194 /// \~english @param [in] region
195 /// cl_region_t * - the region to free
196 /// \~english @param [in] p
197 /// void * - the pointer to region
198 /// \~english @retval true Success
199 /// \~english @retval false Error
200 /// \~english @par Prerequisite
202 /// \~english @par Change of internal state
204 /// \~english @par Conditions of processing failure
206 /// \~english @par Classification
208 /// \~english @par Type
210 /// \~english @par Detail
212 /// \~english @see None
213 ////////////////////////////////////////////////////////////////////////////////////
214 bool CL_RegionFree(cl_region_t *region, void *p); // NOLINT(readability/nolint)
217 /////////////////////////////////////////////////////////////////////////////////////
219 /// \~english @par Brief
220 /// add region cleanup
221 /// \~english @param [in] region
222 /// cl_region_t * - the region to allocate
223 /// \~english @param [in] size
224 /// size_t * - the size to add
225 /// \~english @param [in] align_size
226 /// size_t * - the size to align
227 /// \~english @retval the pointer to region cleanup added
228 /// \~english @par Prerequisite
230 /// \~english @par Change of internal state
232 /// \~english @par Conditions of processing failure
234 /// \~english @par Classification
236 /// \~english @par Type
238 /// \~english @par Detail
240 /// \~english @see None
241 ////////////////////////////////////////////////////////////////////////////////////
242 #define CL_RegionCleanupAdd(region, type, length) \
243 cl_region_cleanup_add(region, sizeof(type) * length, CL_ALIGNOF(type))
244 cl_region_cleanup_t *cl_region_cleanup_add(cl_region_t *region, size_t size, // NOLINT(readability/nolint)
247 /** @}*/ // end of common_library
248 /** @}*/ // end of NativeService
249 /** @}*/ // end of BaseSystem
255 #endif /* _CL_REGION_H_ */ // NOLINT(build/header_guard)
257 /* vim:set ts=8 sw=2 sts=2: */