delayed_destruction_ring.h 716 B

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