• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 BASE_ALLOCATOR_PARTITION_ALLOCATOR_ALLOCATION_GUARD_H_
6 #define BASE_ALLOCATOR_PARTITION_ALLOCATOR_ALLOCATION_GUARD_H_
7 
8 #include "base/allocator/partition_allocator/partition_alloc_base/component_export.h"
9 #include "base/allocator/partition_allocator/partition_alloc_config.h"
10 #include "build/build_config.h"
11 
12 namespace partition_alloc {
13 
14 #if PA_CONFIG(HAS_ALLOCATION_GUARD)
15 
16 // Disallow allocations in the scope. Does not nest.
PA_COMPONENT_EXPORT(PARTITION_ALLOC)17 class PA_COMPONENT_EXPORT(PARTITION_ALLOC) ScopedDisallowAllocations {
18  public:
19   ScopedDisallowAllocations();
20   ~ScopedDisallowAllocations();
21 };
22 
23 // Disallow allocations in the scope. Does not nest.
PA_COMPONENT_EXPORT(PARTITION_ALLOC)24 class PA_COMPONENT_EXPORT(PARTITION_ALLOC) ScopedAllowAllocations {
25  public:
26   ScopedAllowAllocations();
27   ~ScopedAllowAllocations();
28 
29  private:
30   bool saved_value_;
31 };
32 
33 #else
34 
35 struct [[maybe_unused]] ScopedDisallowAllocations {};
36 struct [[maybe_unused]] ScopedAllowAllocations {};
37 
38 #endif  // PA_CONFIG(HAS_ALLOCATION_GUARD)
39 
40 }  // namespace partition_alloc
41 
42 namespace base::internal {
43 
44 using ::partition_alloc::ScopedAllowAllocations;
45 using ::partition_alloc::ScopedDisallowAllocations;
46 
47 }  // namespace base::internal
48 
49 #endif  // BASE_ALLOCATOR_PARTITION_ALLOCATOR_ALLOCATION_GUARD_H_
50