allocation_guard.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright 2021 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef BASE_ALLOCATOR_PARTITION_ALLOCATOR_ALLOCATION_GUARD_H_
  5. #define BASE_ALLOCATOR_PARTITION_ALLOCATOR_ALLOCATION_GUARD_H_
  6. #include "base/allocator/partition_allocator/partition_alloc_base/component_export.h"
  7. #include "base/allocator/partition_allocator/partition_alloc_config.h"
  8. #include "build/build_config.h"
  9. namespace partition_alloc {
  10. #if defined(PA_HAS_ALLOCATION_GUARD)
  11. // Disallow allocations in the scope. Does not nest.
  12. class PA_COMPONENT_EXPORT(PARTITION_ALLOC) ScopedDisallowAllocations {
  13. public:
  14. ScopedDisallowAllocations();
  15. ~ScopedDisallowAllocations();
  16. };
  17. // Disallow allocations in the scope. Does not nest.
  18. class PA_COMPONENT_EXPORT(PARTITION_ALLOC) ScopedAllowAllocations {
  19. public:
  20. ScopedAllowAllocations();
  21. ~ScopedAllowAllocations();
  22. private:
  23. bool saved_value_;
  24. };
  25. #else
  26. struct [[maybe_unused]] ScopedDisallowAllocations{};
  27. struct [[maybe_unused]] ScopedAllowAllocations{};
  28. #endif // defined(PA_HAS_ALLOCATION_GUARD)
  29. } // namespace partition_alloc
  30. namespace base::internal {
  31. using ::partition_alloc::ScopedAllowAllocations;
  32. using ::partition_alloc::ScopedDisallowAllocations;
  33. } // namespace base::internal
  34. #endif // BASE_ALLOCATOR_PARTITION_ALLOCATOR_ALLOCATION_GUARD_H_