LCOV - code coverage report
Current view: top level - core - cfd_init.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 8 8
Test Date: 2026-03-04 10:22:18 Functions: 100.0 % 3 3

            Line data    Source code
       1              : #include "cfd/core/cfd_init.h"
       2              : #include "cfd/core/cfd_status.h"
       3              : #include "cfd_threading_internal.h"
       4              : #include <stdbool.h>
       5              : 
       6              : 
       7              : /* Global initialization state */
       8              : static cfd_atomic_int s_is_initialized = 0;
       9              : 
      10          212 : cfd_status_t cfd_init(void) {
      11              :     // Check if already initialized (fast path)
      12          212 :     if (cfd_atomic_load(&s_is_initialized)) {
      13              :         return CFD_SUCCESS;
      14              :     }
      15              : 
      16              :     // Attempt to transition from 0 (uninitialized) to 1 (initialized)
      17          211 :     if (cfd_atomic_cas(&s_is_initialized, 0, 1)) {
      18              :         /*
      19              :          * This thread won the race to initialize.
      20              :          * Perform global initialization tasks here.
      21              :          */
      22              :         return CFD_SUCCESS;
      23              :     }
      24              :     // Another thread beat us to it or initialization is already done
      25              :     return CFD_SUCCESS;
      26              : }
      27              : 
      28          212 : void cfd_finalize(void) {
      29              :     // Attempt to transition from 1 to 0
      30          212 :     cfd_atomic_cas(&s_is_initialized, 1, 0);
      31          212 : }
      32              : 
      33           84 : int cfd_is_initialized(void) {
      34           84 :     return cfd_atomic_load(&s_is_initialized) ? 1 : 0;
      35              : }
        

Generated by: LCOV version 2.0-1