#ifndef PARTITION_ALLOC_THREAD_CACHE_H_
#define PARTITION_ALLOC_THREAD_CACHE_H_
#include <atomic>
#include <cstdint>
#include <limits>
#include <memory>
#include <optional>
#include "partition_alloc/build_config.h"
#include "partition_alloc/buildflags.h"
#include "partition_alloc/lightweight_quarantine.h"
#include "partition_alloc/partition_alloc-inl.h"
#include "partition_alloc/partition_alloc_base/compiler_specific.h"
#include "partition_alloc/partition_alloc_base/component_export.h"
#include "partition_alloc/partition_alloc_base/thread_annotations.h"
#include "partition_alloc/partition_alloc_base/time/time.h"
#include "partition_alloc/partition_alloc_config.h"
#include "partition_alloc/partition_alloc_constants.h"
#include "partition_alloc/partition_alloc_forward.h"
#include "partition_alloc/partition_bucket_lookup.h"
#include "partition_alloc/partition_freelist_entry.h"
#include "partition_alloc/partition_lock.h"
#include "partition_alloc/partition_stats.h"
#include "partition_alloc/partition_tls.h"
#if PA_BUILDFLAG(PA_ARCH_CPU_X86_64) && PA_BUILDFLAG(HAS_64_BIT_POINTERS)
#include <algorithm>
#endif
namespace partition_alloc {
class ThreadCache;
namespace tools {
#if PA_BUILDFLAG(HAS_64_BIT_POINTERS)
constexpr uintptr_t kNeedle1 = …;
constexpr uintptr_t kNeedle2 = …;
#else
constexpr uintptr_t kNeedle1 = 0xe69e32f3;
constexpr uintptr_t kNeedle2 = 0x9615ee1c;
#endif
constexpr size_t kThreadCacheNeedleArraySize = …;
extern uintptr_t kThreadCacheNeedleArray[kThreadCacheNeedleArraySize];
class HeapDumper;
class ThreadCacheInspector;
}
namespace internal {
extern PA_COMPONENT_EXPORT(PARTITION_ALLOC) PartitionTlsKey g_thread_cache_key;
#if PA_CONFIG(THREAD_CACHE_FAST_TLS)
extern PA_COMPONENT_EXPORT(
PARTITION_ALLOC) thread_local ThreadCache* g_thread_cache;
#endif
}
constexpr internal::base::TimeDelta kMinPurgeInterval = …;
constexpr internal::base::TimeDelta kMaxPurgeInterval = …;
constexpr internal::base::TimeDelta kDefaultPurgeInterval = …;
constexpr size_t kMinCachedMemoryForPurgingBytes = …;
class PA_COMPONENT_EXPORT(PARTITION_ALLOC) ThreadCacheRegistry { … };
constexpr ThreadCacheRegistry::ThreadCacheRegistry() = default;
#if PA_CONFIG(THREAD_CACHE_ENABLE_STATISTICS)
#define PA_INCREMENT_COUNTER(counter) …
#else
#define PA_INCREMENT_COUNTER …
#endif
#if PA_BUILDFLAG(DCHECKS_ARE_ON)
namespace internal {
class ReentrancyGuard { … };
}
#define PA_REENTRANCY_GUARD(x) …
#else
#define PA_REENTRANCY_GUARD …
#endif
class PA_COMPONENT_EXPORT(PARTITION_ALLOC) ThreadCache { … };
PA_ALWAYS_INLINE std::optional<size_t> ThreadCache::MaybePutInCache(
uintptr_t slot_start,
size_t bucket_index) { … }
PA_ALWAYS_INLINE uintptr_t ThreadCache::GetFromCache(size_t bucket_index,
size_t* slot_size) { … }
PA_ALWAYS_INLINE void ThreadCache::PutInBucket(Bucket& bucket,
uintptr_t slot_start) { … }
PA_ALWAYS_INLINE void ThreadCache::RecordAllocation(size_t size) { … }
PA_ALWAYS_INLINE void ThreadCache::RecordDeallocation(size_t size) { … }
}
#endif