#include "Renderive_Id_Allocator.hpp"
#include <atomic>
#include <limits>
#include <stdexcept>
namespace {
template <class Id>
Id allocate_id(std::atomic<Id>& next, const char* message) {
    Id value = next.load(std::memory_order_relaxed);
    for (;;) {
        if (value == 0 || value == std::numeric_limits<Id>::max())
            throw std::overflow_error(message);
        if (next.compare_exchange_weak(value, value + 1, std::memory_order_relaxed))
            return value;
    }
}
std::atomic<Renderable_Id> next_renderable_id{1};
std::atomic<Render_Node_Id> next_node_id{1};
}
Renderable_Id allocate_renderive_renderable_id() {
    return allocate_id(next_renderable_id, "renderable id exhausted");
}
Render_Node_Id allocate_renderive_node_id() {
    return allocate_id(next_node_id, "render node id exhausted");
}
