1 #ifndef HALIDE_RUNTIME_LINKED_LIST_H
2 #define HALIDE_RUNTIME_LINKED_LIST_H
4 #include "../HalideRuntime.h"
58 void clear(
void *user_context);
59 void destroy(
void *user_context);
69 void reclaim(
void *user_context,
EntryType *entry_ptr);
75 size_t entry_count = 0;
110 link_arena =
nullptr;
111 data_arena =
nullptr;
133 typename LinkedList::EntryType *
135 EntryType *entry_ptr = reserve(user_context);
137 front_ptr = entry_ptr;
138 back_ptr = entry_ptr;
143 front_ptr = entry_ptr;
151 EntryType *entry_ptr = reserve(user_context);
153 front_ptr = entry_ptr;
154 back_ptr = entry_ptr;
159 back_ptr = entry_ptr;
183 if (next_ptr !=
nullptr) {
186 front_ptr = next_ptr;
187 reclaim(user_context, remove_ptr);
195 if (prev_ptr !=
nullptr) {
199 reclaim(user_context, remove_ptr);
204 if (
empty() ==
false) {
206 while (remove_ptr !=
nullptr) {
208 reclaim(user_context, remove_ptr);
209 remove_ptr = prev_ptr;
221 if (entry_ptr->
prev_ptr !=
nullptr) {
228 if (entry_ptr->
next_ptr !=
nullptr) {
235 reclaim(user_context, entry_ptr);
241 if (entry_ptr !=
nullptr) {
243 EntryType *new_ptr = reserve(user_context);
247 if (prev_ptr !=
nullptr) {
256 return append(user_context);
262 if (entry_ptr !=
nullptr) {
264 EntryType *new_ptr = reserve(user_context);
268 if (next_ptr !=
nullptr) {
300 return entry_count == 0;
314 LinkedList::reserve(
void *user_context) {
315 EntryType *entry_ptr =
static_cast<EntryType *
>(
316 link_arena->
reserve(user_context,
true));
317 entry_ptr->
value = data_arena->
reserve(user_context,
true);
318 entry_ptr->next_ptr =
nullptr;
319 entry_ptr->prev_ptr =
nullptr;
323 void LinkedList::reclaim(
void *user_context, EntryType *entry_ptr) {
324 void *value_ptr = entry_ptr->value;
325 entry_ptr->value =
nullptr;
326 entry_ptr->next_ptr =
nullptr;
327 entry_ptr->prev_ptr =
nullptr;
328 data_arena->
reclaim(user_context, value_ptr);
329 link_arena->
reclaim(user_context, entry_ptr);
338 #endif // HALIDE_RUNTIME_LINKED_LIST_H