SolidSyslog coverage report
Current view: top level - Core/Source - SolidSyslogPoolAllocator.c (source / functions) Coverage Total Hit
Test: SolidSyslog Lines: 100.0 % 32 32
Test Date: 2026-11-12 23:14:35 Functions: 100.0 % 7 7
Branches: 100.0 % 10 10

             Branch data     Line data    Source code
       1                 :             : /* SPDX-FileCopyrightText: Copyright 2026 Cozens Software Solutions Limited
       2                 :             :  * SPDX-License-Identifier: PolyForm-Noncommercial-1.0.0 OR LicenseRef-PolyForm-Internal-Use-1.0.0 OR LicenseRef-COSOSO-Commercial
       3                 :             :  */
       4                 :             : 
       5                 :             : #include "SolidSyslogPoolAllocator.h"
       6                 :             : 
       7                 :             : #include <stddef.h>
       8                 :             : 
       9                 :             : #include "SolidSyslogConfigLock.h"
      10                 :             : 
      11                 :             : static bool PoolAllocator_TryClaim(struct SolidSyslogPoolAllocator* self, size_t index);
      12                 :             : static inline bool PoolAllocator_SlotIsFree(const struct SolidSyslogPoolAllocator* self, size_t index);
      13                 :             : static inline bool PoolAllocator_SlotIsInUse(const struct SolidSyslogPoolAllocator* self, size_t index);
      14                 :             : static inline void PoolAllocator_MarkInUse(struct SolidSyslogPoolAllocator* self, size_t index);
      15                 :             : static inline void PoolAllocator_MarkFree(struct SolidSyslogPoolAllocator* self, size_t index);
      16                 :             : 
      17                 :       63945 : size_t SolidSyslogPoolAllocator_AcquireFirstFree(struct SolidSyslogPoolAllocator* self)
      18                 :             : {
      19                 :       63945 :     size_t acquired = 0U;
      20   [ +  +  +  + ]:       64309 :     while ((acquired < self->Count) && !PoolAllocator_TryClaim(self, acquired))
      21                 :             :     {
      22                 :         364 :         acquired++;
      23                 :             :     }
      24                 :       63945 :     return acquired;
      25                 :             : }
      26                 :             : 
      27                 :       64116 : static bool PoolAllocator_TryClaim(struct SolidSyslogPoolAllocator* self, size_t index)
      28                 :             : {
      29                 :       64116 :     bool claimed = false;
      30                 :       64116 :     SolidSyslog_LockConfig();
      31         [ +  + ]:       64116 :     if (PoolAllocator_SlotIsFree(self, index))
      32                 :             :     {
      33                 :       63752 :         PoolAllocator_MarkInUse(self, index);
      34                 :       63752 :         claimed = true;
      35                 :             :     }
      36                 :       64116 :     SolidSyslog_UnlockConfig();
      37                 :       64116 :     return claimed;
      38                 :             : }
      39                 :             : 
      40                 :       64116 : static inline bool PoolAllocator_SlotIsFree(const struct SolidSyslogPoolAllocator* self, size_t index)
      41                 :             : {
      42                 :       64116 :     return !PoolAllocator_SlotIsInUse(self, index);
      43                 :             : }
      44                 :             : 
      45                 :      127936 : static inline bool PoolAllocator_SlotIsInUse(const struct SolidSyslogPoolAllocator* self, size_t index)
      46                 :             : {
      47                 :      127936 :     return self->InUse[index];
      48                 :             : }
      49                 :             : 
      50                 :       63752 : static inline void PoolAllocator_MarkInUse(struct SolidSyslogPoolAllocator* self, size_t index)
      51                 :             : {
      52                 :       63752 :     self->InUse[index] = true;
      53                 :       63752 : }
      54                 :             : 
      55                 :       63820 : bool SolidSyslogPoolAllocator_FreeIfInUse(
      56                 :             :     struct SolidSyslogPoolAllocator* self,
      57                 :             :     size_t index,
      58                 :             :     SolidSyslogPoolCleanup cleanup,
      59                 :             :     void* context
      60                 :             : )
      61                 :             : {
      62                 :       63820 :     SolidSyslog_LockConfig();
      63                 :       63820 :     bool released = PoolAllocator_SlotIsInUse(self, index);
      64         [ +  + ]:       63820 :     if (released)
      65                 :             :     {
      66         [ +  + ]:       63753 :         if (cleanup != NULL)
      67                 :             :         {
      68                 :       63743 :             cleanup(index, context);
      69                 :             :         }
      70                 :       63753 :         PoolAllocator_MarkFree(self, index);
      71                 :             :     }
      72                 :       63820 :     SolidSyslog_UnlockConfig();
      73                 :       63820 :     return released;
      74                 :             : }
      75                 :             : 
      76                 :       63753 : static inline void PoolAllocator_MarkFree(struct SolidSyslogPoolAllocator* self, size_t index)
      77                 :             : {
      78                 :       63753 :     self->InUse[index] = false;
      79                 :       63753 : }
        

Generated by: LCOV version 2.0-1