#pragma once #include "compat/bionic_host_libc_runtime.h" #include #include namespace mocktail::compat { // Heap accounting is a sampled statistic. A glibc scan walks free lists while // holding arena locks, so back-to-back Android queries share a recent sample. // The scan runs outside this mutex; concurrent callers can use the last complete // sample without waiting for another allocator walk. class AllocatorSnapshotCache { public: static constexpr std::uint64_t kRefreshNs=500'000'000ULL; template BionicMallinfoSnapshot Read(std::uint64_t now,Reader reader) noexcept { std::unique_lock lock(mutex_); if(refreshing_ || (initialized_ && now