| // Copyright 2021 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #ifndef BASE_ALLOCATOR_PARTITION_ALLOCATOR_ALLOCATION_GUARD_H_ |
| #define BASE_ALLOCATOR_PARTITION_ALLOCATOR_ALLOCATION_GUARD_H_ |
| |
| #include "base/allocator/partition_allocator/partition_alloc_config.h" |
| #include "base/base_export.h" |
| #include "build/build_config.h" |
| |
| namespace partition_alloc { |
| |
| #if defined(PA_HAS_ALLOCATION_GUARD) |
| |
| // Disallow allocations in the scope. Does not nest. |
| class BASE_EXPORT ScopedDisallowAllocations { |
| public: |
| ScopedDisallowAllocations(); |
| ~ScopedDisallowAllocations(); |
| }; |
| |
| // Disallow allocations in the scope. Does not nest. |
| class BASE_EXPORT ScopedAllowAllocations { |
| public: |
| ScopedAllowAllocations(); |
| ~ScopedAllowAllocations(); |
| |
| private: |
| bool saved_value_; |
| }; |
| |
| #else |
| |
| struct [[maybe_unused]] ScopedDisallowAllocations{}; |
| struct [[maybe_unused]] ScopedAllowAllocations{}; |
| |
| #endif // defined(PA_HAS_ALLOCATION_GUARD) |
| |
| } // namespace partition_alloc |
| |
| namespace base::internal { |
| |
| using ::partition_alloc::ScopedAllowAllocations; |
| using ::partition_alloc::ScopedDisallowAllocations; |
| |
| } // namespace base::internal |
| |
| #endif // BASE_ALLOCATOR_PARTITION_ALLOCATOR_ALLOCATION_GUARD_H_ |