| 1 |
/* File: universal_arena_list.inl; Copyright and License: see below */ |
| 2 |
|
| 3 |
#include "u8/u8_log.h" |
| 4 |
#include <stdint.h> |
| 5 |
#include <assert.h> |
| 6 |
|
| 7 |
static inline void universal_arena_list_init( universal_arena_list_t *this_, |
| 8 |
universal_memory_arena_t *allocator ) |
| 9 |
{ |
| 10 |
assert( allocator != NULL ); |
| 11 |
(*this_).begin = NULL; |
| 12 |
(*this_).allocator = allocator; |
| 13 |
} |
| 14 |
|
| 15 |
static inline void universal_arena_list_destroy( universal_arena_list_t *this_ ) |
| 16 |
{ |
| 17 |
assert( (*this_).allocator != NULL ); |
| 18 |
(*this_).allocator = NULL; |
| 19 |
(*this_).begin = NULL; |
| 20 |
} |
| 21 |
|
| 22 |
static inline u8_error_t universal_arena_list_append( universal_arena_list_t *this_, void* element ) |
| 23 |
{ |
| 24 |
assert( (*this_).allocator != NULL ); |
| 25 |
u8_error_t err = U8_ERROR_NONE; |
| 26 |
|
| 27 |
universal_arena_list_element_t *new_ele; |
| 28 |
err = universal_memory_arena_get_block( (*this_).allocator, sizeof(universal_arena_list_element_t), (void**)&new_ele ); |
| 29 |
if ( err == U8_ERROR_NONE ) |
| 30 |
{ |
| 31 |
universal_arena_list_element_init( new_ele, element, NULL ); |
| 32 |
|
| 33 |
if ( (*this_).begin == NULL ) |
| 34 |
{ |
| 35 |
(*this_).begin = new_ele; |
| 36 |
} |
| 37 |
else |
| 38 |
{ |
| 39 |
universal_arena_list_element_t *find_last = (*this_).begin; |
| 40 |
for ( bool finished = false; ( ! finished ); ) |
| 41 |
{ |
| 42 |
if ( universal_arena_list_element_get_next( find_last ) == NULL ) |
| 43 |
{ |
| 44 |
universal_arena_list_element_set_next( find_last, new_ele ); |
| 45 |
finished = true; |
| 46 |
} |
| 47 |
else |
| 48 |
{ |
| 49 |
find_last = universal_arena_list_element_get_next( find_last ); |
| 50 |
} |
| 51 |
} |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
return err; |
| 56 |
} |
| 57 |
|
| 58 |
static inline universal_arena_list_element_t* universal_arena_list_get_begin( universal_arena_list_t *this_ ) |
| 59 |
{ |
| 60 |
return (*this_).begin; |
| 61 |
} |
| 62 |
|
| 63 |
static inline universal_arena_list_element_t* universal_arena_list_get_end( universal_arena_list_t *this_ ) |
| 64 |
{ |
| 65 |
return NULL; |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
/* |
| 70 |
Copyright 2021-2026 Andreas Warnke |
| 71 |
|
| 72 |
Licensed under the Apache License, Version 2.0 (the "License"); |
| 73 |
you may not use this file except in compliance with the License. |
| 74 |
You may obtain a copy of the License at |
| 75 |
|
| 76 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 77 |
|
| 78 |
Unless required by applicable law or agreed to in writing, software |
| 79 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 80 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 81 |
See the License for the specific language governing permissions and |
| 82 |
limitations under the License. |
| 83 |
*/ |