LCOV - code coverage report
Current view: top level - u8stream/include/u8arena - universal_memory_arena.inl (source / functions) Hit Total Coverage
Test: crystal-facet-uml_v1.61.0_covts Lines: 24 24 100.0 %
Date: 2024-10-26 21:44:38 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /* File: universal_memory_arena.inl; Copyright and License: see below */
       2             : 
       3             : #include <assert.h>
       4             : 
       5           2 : static inline void universal_memory_arena_init ( universal_memory_arena_t *this_,
       6             :                                                  void* mem_buf_start,
       7             :                                                  size_t mem_buf_size )
       8             : {
       9           2 :     assert( mem_buf_start != NULL );
      10           2 :     (*this_).int_buf_start = mem_buf_start;
      11           2 :     (*this_).int_buf_size = mem_buf_size / sizeof(int);
      12           2 :     (*this_).int_buf_used = 0;
      13           2 : }
      14             : 
      15           2 : static inline void universal_memory_arena_destroy ( universal_memory_arena_t *this_ )
      16             : {
      17           2 :     assert( (*this_).int_buf_start != NULL );
      18           2 :     (*this_).int_buf_start = NULL;
      19           2 : }
      20             : 
      21           1 : static inline void universal_memory_arena_reset ( universal_memory_arena_t *this_ )
      22             : {
      23           1 :     (*this_).int_buf_used = 0;
      24           1 : }
      25             : 
      26          12 : static inline u8_error_t universal_memory_arena_get_block ( universal_memory_arena_t *this_,
      27             :                                                             size_t block_size,
      28             :                                                             void **out_block )
      29             : {
      30          12 :     assert( out_block != NULL );
      31          12 :     u8_error_t err = U8_ERROR_NONE;
      32             : 
      33          12 :     const size_t requested_ints = ( block_size + sizeof(int) - 1 ) / sizeof(int);
      34             : 
      35          12 :     if (( (*this_).int_buf_used + requested_ints ) > (*this_).int_buf_size )
      36             :     {
      37           2 :         err = U8_ERROR_ARRAY_BUFFER_EXCEEDED;
      38           2 :         *out_block = NULL;
      39             :     }
      40             :     else
      41             :     {
      42          10 :         err = U8_ERROR_NONE;
      43          10 :         *out_block = &( (*this_).int_buf_start[(*this_).int_buf_used] );
      44          10 :         (*this_).int_buf_used += requested_ints;
      45             :     }
      46             : 
      47          12 :     return err;
      48             : }
      49             : 
      50             : 
      51             : /*
      52             : Copyright 2021-2024 Andreas Warnke
      53             : 
      54             : Licensed under the Apache License, Version 2.0 (the "License");
      55             : you may not use this file except in compliance with the License.
      56             : You may obtain a copy of the License at
      57             : 
      58             :     http://www.apache.org/licenses/LICENSE-2.0
      59             : 
      60             : Unless required by applicable law or agreed to in writing, software
      61             : distributed under the License is distributed on an "AS IS" BASIS,
      62             : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      63             : See the License for the specific language governing permissions and
      64             : limitations under the License.
      65             : */

Generated by: LCOV version 1.16