inline static void debug_check_empty()

in src/mem/globalalloc.h [86:153]


  inline static void debug_check_empty(bool* result = nullptr)
  {
#ifndef SNMALLOC_PASS_THROUGH
    static_assert(
      SharedStateHandle::Options.CoreAllocIsPoolAllocated,
      "Global status is available only for pool-allocated configurations");
    // This is a debugging function. It checks that all memory from all
    // allocators has been freed.
    auto* alloc = AllocPool<SharedStateHandle>::iterate();

#  ifdef SNMALLOC_TRACING
    std::cout << "debug check empty: first " << alloc << std::endl;
#  endif
    bool done = false;
    bool okay = true;

    while (!done)
    {
#  ifdef SNMALLOC_TRACING
      std::cout << "debug_check_empty: Check all allocators!" << std::endl;
#  endif
      done = true;
      alloc = AllocPool<SharedStateHandle>::iterate();
      okay = true;

      while (alloc != nullptr)
      {
#  ifdef SNMALLOC_TRACING
        std::cout << "debug check empty: " << alloc << std::endl;
#  endif
        // Check that the allocator has freed all memory.
        // repeat the loop if empty caused message sends.
        if (alloc->debug_is_empty(&okay))
        {
          done = false;
#  ifdef SNMALLOC_TRACING
          std::cout << "debug check empty: sent messages " << alloc
                    << std::endl;
#  endif
        }

#  ifdef SNMALLOC_TRACING
        std::cout << "debug check empty: okay = " << okay << std::endl;
#  endif
        alloc = AllocPool<SharedStateHandle>::iterate(alloc);
      }
    }

    if (result != nullptr)
    {
      *result = okay;
      return;
    }

    // Redo check so abort is on allocator with allocation left.
    if (!okay)
    {
      alloc = AllocPool<SharedStateHandle>::iterate();
      while (alloc != nullptr)
      {
        alloc->debug_is_empty(nullptr);
        alloc = AllocPool<SharedStateHandle>::iterate(alloc);
      }
    }
#else
    UNUSED(result);
#endif
  }