mirror of
https://git.eden-emu.dev/eden-emu/eden.git
synced 2026-09-03 03:09:13 +00:00
[TEST] Refactor on memory collections
This commit is contained in:
committed by
CamilleLaVey
parent
8d7f992792
commit
b8135a3e47
@@ -0,0 +1,51 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <deque>
|
||||
#include <utility>
|
||||
|
||||
#include "common/common_types.h"
|
||||
|
||||
namespace VideoCommon {
|
||||
|
||||
template <typename T>
|
||||
class DeferredDestructionQueue {
|
||||
public:
|
||||
void Push(T&& object, u64 sync_point) {
|
||||
entries.emplace_back(std::move(object), sync_point);
|
||||
}
|
||||
|
||||
void Reclaim(u64 completed_sync_point) {
|
||||
while (!entries.empty() && entries.front().sync_point <= completed_sync_point) {
|
||||
entries.pop_front();
|
||||
}
|
||||
}
|
||||
|
||||
void Clear() {
|
||||
entries.clear();
|
||||
}
|
||||
|
||||
[[nodiscard]] size_t Size() const noexcept {
|
||||
return entries.size();
|
||||
}
|
||||
|
||||
[[nodiscard]] bool Empty() const noexcept {
|
||||
return entries.empty();
|
||||
}
|
||||
|
||||
private:
|
||||
struct Entry {
|
||||
Entry(T&& object_, u64 sync_point_) noexcept
|
||||
: object{std::move(object_)}, sync_point{sync_point_} {}
|
||||
|
||||
T object;
|
||||
u64 sync_point;
|
||||
};
|
||||
|
||||
std::deque<Entry> entries;
|
||||
};
|
||||
|
||||
} // namespace VideoCommon
|
||||
Reference in New Issue
Block a user