delayed_destruction_ring.h 697 B

12345678910111213141516171819202122232425262728293031
  1. // SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <array>
  5. #include <cstddef>
  6. #include <utility>
  7. #include <vector>
  8. namespace VideoCommon {
  9. /// Container to push objects to be destroyed a few ticks in the future
  10. template <typename T, size_t TICKS_TO_DESTROY>
  11. class DelayedDestructionRing {
  12. public:
  13. void Tick() {
  14. index = (index + 1) % TICKS_TO_DESTROY;
  15. elements[index].clear();
  16. }
  17. void Push(T&& object) {
  18. elements[index].push_back(std::move(object));
  19. }
  20. private:
  21. size_t index = 0;
  22. std::array<std::vector<T>, TICKS_TO_DESTROY> elements;
  23. };
  24. } // namespace VideoCommon