xref: /aosp_15_r20/external/cronet/base/allocator/partition_allocator/src/partition_alloc/extended_api.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2021 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef PARTITION_ALLOC_EXTENDED_API_H_
6 #define PARTITION_ALLOC_EXTENDED_API_H_
7 
8 #include "partition_alloc/partition_alloc_buildflags.h"
9 #include "partition_alloc/partition_root.h"
10 #include "partition_alloc/partition_stats.h"
11 #include "partition_alloc/thread_cache.h"
12 
13 namespace partition_alloc::internal {
14 // Get allocation stats for the thread cache partition on the current
15 // thread. See the documentation of ThreadAllocStats for details.
16 ThreadAllocStats GetAllocStatsForCurrentThread();
17 
18 // Creates a scope for testing which:
19 // - if the given |root| is a default malloc root for the entire process,
20 //   enables the thread cache for the entire process.
21 //   (This may happen if UsePartitionAllocAsMalloc is enabled.)
22 // - otherwise, disables the thread cache for the entire process, and
23 //   replaces it with a thread cache for |root|.
24 // This class is unsafe to run if there are multiple threads running
25 // in the process.
26 class ThreadCacheProcessScopeForTesting {
27  public:
28   explicit ThreadCacheProcessScopeForTesting(PartitionRoot* root);
29   ~ThreadCacheProcessScopeForTesting();
30 
31   ThreadCacheProcessScopeForTesting() = delete;
32 
33  private:
34   PartitionRoot* root_ = nullptr;
35 #if BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)
36   bool regular_was_enabled_ = false;
37 #endif
38 };
39 
40 }  // namespace partition_alloc::internal
41 
42 #endif  // PARTITION_ALLOC_EXTENDED_API_H_
43