Files
Destrum/destrum/src/Graphics/DeletionQueue.cpp
T

40 lines
1.1 KiB
C++

#include <destrum/Graphics/DeletionQueue.h>
#include <cassert>
#include <exception>
#include <spdlog/spdlog.h>
void DeletionQueue::push(std::uint64_t retiredInFrame, std::function<void()>&& deleter)
{
// entries stay sorted by frame, flush only has to look at the front
assert(entries.empty() || entries.back().frame <= retiredInFrame);
entries.push_back(Entry{retiredInFrame, std::move(deleter)});
}
void DeletionQueue::flush(std::uint64_t lastCompletedFrame)
{
while (!entries.empty() && entries.front().frame <= lastCompletedFrame) {
auto deleter = std::move(entries.front().deleter);
entries.pop_front();
try {
deleter();
} catch (const std::exception& e) {
spdlog::error("DeletionQueue: deleter threw: {}", e.what());
}
}
}
void DeletionQueue::flushAll()
{
while (!entries.empty()) {
auto deleter = std::move(entries.front().deleter);
entries.pop_front();
try {
deleter();
} catch (const std::exception& e) {
spdlog::error("DeletionQueue: deleter threw: {}", e.what());
}
}
}