SolidSyslog coverage report
Current view: top level - Platform/VxWorks64/Source - SolidSyslogVxWorks64AtomicCounterStatic.c (source / functions) Coverage Total Hit
Test: SolidSyslog Lines: 100.0 % 25 25
Test Date: 2026-11-12 23:14:35 Functions: 100.0 % 4 4
Branches: 100.0 % 12 12

             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 "SolidSyslogVxWorks64AtomicCounter.h"
       6                 :             : 
       7                 :             : #include <stdbool.h>
       8                 :             : #include <stddef.h>
       9                 :             : 
      10                 :             : #include "SolidSyslogError.h"
      11                 :             : #include "SolidSyslogErrorCategory.h"
      12                 :             : #include "SolidSyslogNullAtomicCounter.h"
      13                 :             : #include "SolidSyslogPoolAllocator.h"
      14                 :             : #include "SolidSyslogPrival.h"
      15                 :             : #include "SolidSyslogTunables.h"
      16                 :             : #include "SolidSyslogVxWorks64AtomicCounterErrors.h"
      17                 :             : #include "SolidSyslogVxWorks64AtomicCounterPrivate.h"
      18                 :             : 
      19                 :             : struct SolidSyslogAtomicCounter;
      20                 :             : 
      21                 :             : static inline size_t VxWorks64AtomicCounter_IndexFromHandle(const struct SolidSyslogAtomicCounter* base);
      22                 :             : static inline void VxWorks64AtomicCounter_CleanupAtIndex(size_t index, void* context);
      23                 :             : 
      24                 :             : static bool VxWorks64AtomicCounter_InUse[SOLIDSYSLOG_ATOMIC_COUNTER_POOL_SIZE];
      25                 :             : static struct SolidSyslogVxWorks64AtomicCounter VxWorks64AtomicCounter_Pool[SOLIDSYSLOG_ATOMIC_COUNTER_POOL_SIZE];
      26                 :             : static struct SolidSyslogPoolAllocator VxWorks64AtomicCounter_Allocator = {
      27                 :             :     VxWorks64AtomicCounter_InUse,
      28                 :             :     SOLIDSYSLOG_ATOMIC_COUNTER_POOL_SIZE
      29                 :             : };
      30                 :             : 
      31                 :          75 : struct SolidSyslogAtomicCounter* SolidSyslogVxWorks64AtomicCounter_Create(void)
      32                 :             : {
      33                 :          75 :     size_t index = SolidSyslogPoolAllocator_AcquireFirstFree(&VxWorks64AtomicCounter_Allocator);
      34                 :          75 :     struct SolidSyslogAtomicCounter* handle = SolidSyslogNullAtomicCounter_Get();
      35         [ +  + ]:          75 :     if (SolidSyslogPoolAllocator_IndexIsValid(&VxWorks64AtomicCounter_Allocator, index) == true)
      36                 :             :     {
      37                 :          71 :         SolidSyslogVxWorks64AtomicCounter_Initialise(&VxWorks64AtomicCounter_Pool[index].Base);
      38                 :          71 :         handle = &VxWorks64AtomicCounter_Pool[index].Base;
      39                 :             :     }
      40                 :             :     else
      41                 :             :     {
      42                 :           4 :         VxWorks64AtomicCounter_Report(
      43                 :             :             SOLIDSYSLOG_POOL_EXHAUSTED_SEVERITY,
      44                 :             :             SOLIDSYSLOG_CAT_POOL_EXHAUSTED,
      45                 :             :             SOLIDSYSLOG_ATOMIC_COUNTER_ERROR_POOL_EXHAUSTED
      46                 :             :         );
      47                 :             :     }
      48                 :          75 :     return handle;
      49                 :             : }
      50                 :             : 
      51                 :          78 : void SolidSyslogVxWorks64AtomicCounter_Destroy(struct SolidSyslogAtomicCounter* base)
      52                 :             : {
      53                 :          78 :     size_t index = VxWorks64AtomicCounter_IndexFromHandle(base);
      54   [ +  +  +  + ]:         150 :     bool released = SolidSyslogPoolAllocator_IndexIsValid(&VxWorks64AtomicCounter_Allocator, index) &&
      55                 :          72 :                     SolidSyslogPoolAllocator_FreeIfInUse(
      56                 :             :                         &VxWorks64AtomicCounter_Allocator,
      57                 :             :                         index,
      58                 :             :                         VxWorks64AtomicCounter_CleanupAtIndex,
      59                 :             :                         NULL
      60                 :             :                     );
      61         [ +  + ]:          78 :     if (!released)
      62                 :             :     {
      63                 :           7 :         VxWorks64AtomicCounter_Report(
      64                 :             :             SOLIDSYSLOG_UNKNOWN_DESTROY_SEVERITY,
      65                 :             :             SOLIDSYSLOG_CAT_UNKNOWN_DESTROY,
      66                 :             :             SOLIDSYSLOG_ATOMIC_COUNTER_ERROR_UNKNOWN_DESTROY
      67                 :             :         );
      68                 :             :     }
      69                 :          78 : }
      70                 :             : 
      71                 :          78 : static inline size_t VxWorks64AtomicCounter_IndexFromHandle(const struct SolidSyslogAtomicCounter* base)
      72                 :             : {
      73                 :          78 :     size_t result = SOLIDSYSLOG_ATOMIC_COUNTER_POOL_SIZE;
      74         [ +  + ]:          84 :     for (size_t poolIndex = 0U; poolIndex < SOLIDSYSLOG_ATOMIC_COUNTER_POOL_SIZE; poolIndex++)
      75                 :             :     {
      76         [ +  + ]:          78 :         if (base == &VxWorks64AtomicCounter_Pool[poolIndex].Base)
      77                 :             :         {
      78                 :          72 :             result = poolIndex;
      79                 :          72 :             break;
      80                 :             :         }
      81                 :             :     }
      82                 :          78 :     return result;
      83                 :             : }
      84                 :             : 
      85                 :          71 : static inline void VxWorks64AtomicCounter_CleanupAtIndex(size_t index, void* context)
      86                 :             : {
      87                 :             :     (void) context;
      88                 :          71 :     SolidSyslogVxWorks64AtomicCounter_Cleanup(&VxWorks64AtomicCounter_Pool[index].Base);
      89                 :          71 : }
        

Generated by: LCOV version 2.0-1